Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Customizing Forms Creating Relationships

user_id is not saving in the statuses table

So I'm working through this project with Rails 4 and I've altered the code to make it work thus far. Specifically I added:

def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) << :first_name << :last_name << :profile_name devise_parameter_sanitizer.for(:account_update) << :first_name << :last_name << :profile_name end

to my application controller and now first_name etc... are saving in the user database, whereas before they were nil.

The problem I'm having now is that although I added user_id in the migration in the way specified by the tutorials, it doesn't seem to be associating correctly. I had a look at the database tables in Sqlite browser and in the status table, under the user_id field for a particular user, is just says NULL.

What am I missing? All help appreciated. Thanks.

1 Answer

Rodrigo Castro
Rodrigo Castro
15,652 Points

Hi Kairos,

Try adding :user_id in the hash in the 'status_params' function inside the Statuses_Controller.rb as shown bellow:

def status_params params.require(:status).permit(<<ADD USER_ID HERE>>, :name, :content) end

hope it helps :)