I have an array field in my model and I'm trying to update it.
My strong parameters method below
def post_params params["post"]["categories"] = params["post"]["categories"].split(",") params.require(:post).permit(:name, :email, :categories) end
My action in my controller is as follows
def update post = Post.find(params[:id] if post and post.update_attributes(post_params) redirect_to root_url else redirect_to posts_url end end
However, whenever I send an update message, in my development log I see
Unpermitted parameters: categories
Past parameters:
Parameters: {"utf8"=>"β", "authenticity_token"=>"auth token", "id"=>"10", "post"=>{"name"=>"Toni Mitchell", "email"=>"eileen_hansen@hayetokes.info", "categories"=>",2"}}
I want to think that this has something to do with the fact that the categories attribute is an array, since everything else looks good. Again, I could be wrong. So what happened to my code and why I do not allow me to save the category field when it is explicitly allowed? Thank.
ruby ruby-on-rails ruby-on-rails-4 strong-parameters
jason328 Jul 25 '13 at 21:06 2013-07-25 21:06
source share