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

Rails & strong_parameters 'required parameter missing'

I'm working on creating 'retweet'(restream) functionality for one of my projects, but I keep running into this error:

Required parameter missing: restream

I'm not sure what I'm missing here. Here's my setup. Any ideas?

Models

#app/models/member.rb
Class Member < ActiveRecord::Base
    has_many :statuses
end

#app/models/status.rb
Class Status< ActiveRecord::Base
    belongs_to :member
    has_many :restreams, class_name: "Status", foreign_key: "restream_id"
end

Restream

#config/routes.rb
resources :statuses do
    member do
        post :retweet
    end
end

#app/controllers/statuses_controller.rb
def restream
    @restream = Status.new(restream_params)
    @restream.save
end

private

def restream_params
    params.require(:restream).permit(:restream_id, :content).merge(member_id: current_user.id)
end

#app/views/statuses/show.html.erb
<%= link_to image_tag("Re-Stream 3.png", class: "act_actions", title: "Restream", alt: "Restream"), restream_status_path(status.id), method: :post, :class => "btn restream" %>

1 Answer

You're not passing any params into the controller from your link_to. You need something like this:

<%= link_to image_tag("Re-Stream 3.png", class: "act_actions", title: "Restream", alt: "Restream"), restream_status_path(status.id, restream: my_restream_object), method: :post, :class => "btn restream" %>

Notice where I'm actually passing my_restream_object into the path as a URL parameter named restream.

Hope that helps!

Also, your route is called retweet instead of restream. :)

Sean Gaffney Ok that makes sense. So should the object I'm trying to pass be the actual status? Something like:

restream_status_path(status.id, restream: status)