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 trialMatthew Gomez
395 PointsWhen using Rails 4. You need to tweek the code a bit.
- So the first step is adjusting your create method in statuses. When we create a status, we want to make sure the status know to attach itself to a user. in statuses controller your first few lines in the "create" method should look like this:
def create @status = Status.new(status_params) @status.user= current_user //this is the new stuff, so in your "_form" file now, the code knows what you mean when you say "user".
- Now we need to allow the user_id to be permitted. right now we only allow name and content. So to do that, at the bottom of the statuses controller, your permitted params method should look like this:
def status_params params.require(:status).permit(:user_id, :content) end
- So far so good, but we need to manual associate the then last step is to adjust the status model! This associates the user model to the status model:
class Status < ActiveRecord::Base belongs_to :user end