mengu on web programming.

Ruby on Rails Unprocessable Entity Error

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.

Tags:

Comments

No comments made for this post.

Leave a Response

No HTML allowed. You can use markdown.
Name*:
E-Mail* (not published):
Web site:
Response: