Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an html id to a form_for tag in rails?

I'm trying to add an id tag to a form that I'm creating in rails. The beginning of the form has the following code:

<%= form_for(@user) do |f| %>

Is it possible for me to add an id to the form_for embedded ruby, or do I have to create a form_tag field and add the id there? If I have to create a form_tag field, how do I add the id and create the form_tag field properly? Thank you very much!

like image 540
user1483441 Avatar asked Jul 08 '12 14:07

user1483441


3 Answers

try this <%= form_for @user, :url => "controller action url", :html => {:id => "Blabla"} do |f| %>

EDIT: If you don't want custom action URL then you can use this as well <%= form_for @user, html: {id: "BlaBla"} do |f| %>

like image 173
abhas Avatar answered Oct 10 '22 15:10

abhas


One more way: <%= form_for @user, html: {id: :form_id } do |f| %>

like image 39
Priyanko Avatar answered Oct 10 '22 14:10

Priyanko


This is new syntax

<%= form_for @user, html: {id: "my_form"} do |f| %> <% end %>

like image 38
gsumk Avatar answered Oct 10 '22 13:10

gsumk