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
Dario Hunt
2,245 PointsRails & 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
Sean Gaffney
Front End Web Development Techdegree Student 2,560 PointsYou'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!
Sean Gaffney
Front End Web Development Techdegree Student 2,560 PointsSean Gaffney
Front End Web Development Techdegree Student 2,560 PointsAlso, your route is called
retweetinstead ofrestream. :)Dario Hunt
2,245 PointsDario Hunt
2,245 PointsSean 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)