Reputation: 1795
I have a rails 4 app on heroku, users can choose an option from a drop down menu ( course name) then click post, and the post will appear on the index page. Someone was able to create a post with an option that was not in the drop down menu at all, how is this possible? What can I do about it?
Upvotes: 0
Views: 33
Reputation: 1681
First, the problem. It's very easy to recreate it using chrome developer. Here's the steps on recreating the error
Now the solution:
I will just add a validation that checks weather the value passed in is part of the options in the dropdown http://edgeguides.rubyonrails.org/active_record_validations.html#inclusion
Upvotes: 1
Reputation: 878
Put your options of drop-down menu to private method and permit only those values under your controller. No need to provide attr_accessible under your model if you are writing over there.
Upvotes: 1