Ruby on Rails Unprocessable Entity Error
2009-11-10 11:03:31 | 0 Comment
While I was trying to complete a Ruby on Rails project of mine, I had this error came up. Probably other developers will face it too. And you probably didn't create your form with form_for helper but instead you have written it yourself. Don't worry that's not bad. Rails is slow itself, stop making it slower by using the helpers. Here is the solution:
Don't forget to add "authenticitytoken" as a hidden input to your form. With formfor helper, it adds this input automatically but we forget to include it in our form. So all you should do is:
<input type="hidden" name="authenticity_token" value="@token" />
How you will get @token local variable? In your controller, you should have this line:
@token = session[:_csrf_token]
You are just fine after this.

Comments
Leave a Response