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

User ID doesn't save after adding it to Status Form View

After adding in the following

<%= f.input :user_id %> to the Status Form View I go to try and submit it and instead of getting the expected error because the attribute isn't set as accessible the form submits, but doesn't even pass the user_id.

Looking into the terminal for any errors I see this:

Unpermitted parameters: user_id (0.1ms) begin transaction SQL (3.4ms) INSERT INTO "statuses" ("content", "created_at", "updated_at") VALUES (?, ?, ?) [["content", "ABC"], ["created_at", Sun, 11 Aug 2013 09:13:16 UTC +00:00], ["updated_at", Sun, 11 Aug 2013 09:13:16 UTC +00:00]]

Whether I set the user_id to accessible or not via:

attr_accessible :content, :user_id

It doesn't save the value, and thus when I go to edit the status that was added, user_id isn't pulled because it's never saved.(Confirmed via rails console as well).

What do I have to do to make user_id a permitted attribute ?

Thanks.

1 Answer

Andrew,

Yes I was, but I got passed this issue by inspecting the Status Controller and adding user_id to status_params like so.

def status_params params.require(:status).permit(:name, :content, :user_id) end

Not sure where I missed anything that would cause this, but all is well that ends well.

Thanks for checking in though.

-Seth