I am trying to create a form where I am putting the hidden value which is generating an array which is like :
"comment"=>{"comment"=>"sss", "feed_id"=>"354"}, "commit"=>"Comment"}
But when I am trying to use in controller with permit it produce an error my controller query is like this :
@feeds= Feed.find(params["comment"]["feed_id"])
This @feeds work great but when I am trying to use this with permit params it is showing error
ActionController::ParameterMissing (param is missing or the value is empty: feed):
To permit I am using this query :
def feed_params
#params.require(:feed).permit(comment: :feed_id)
params.require(:feed).permit(comment: [ :feed_id, :comment ])
#params[:market_place]
end
When I am adding it here in my controller like this :
@feeds= Feed.find(feed_params)
I am getting this error
ActionController::ParameterMissing (param is missing or the value is empty: feed):
And this is my form :
<%= form_for(@comment,:remote => true) do |f| %>
<%= f.text_area :comment, class:"form-control post required" %>
<%= f.hidden_field :feed_id, {:value => @feed} %>
If you write your feed_params
to require(:feed)
, then Rails will expect params
to have a "feed"
key and value, which does not. Your form is for comments , so you actually define a comment_params
method. Define it like this:
def comment_params
params.require(:comment).permit(:comment, :feed_id)
end
And then find your Feed like this:
@feeds= Feed.find(comment_params["feed_id"])
And you should be all set.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.