Questions tagged [form-for]

Form helper to bind a form to a model object in Rails.

form_for is a helper to create a form binded to a model object as described in the official guide. Using this helper ensures the built HTML form will use the right name's, id's and default values.

930 questions
177
votes
4 answers

rails simple_form - hidden field - create?

How can you have a hidden field with simple form? The following code: = simple_form_for @movie do |f| = f.hidden :title, "some value" = f.button :submit results in this error: undefined method `hidden' for…
126
votes
3 answers

form_for with nested resources

I have a two-part question about form_for and nested resources. Let's say I'm writing a blog engine and I want to relate a comment to an article. I've defined a nested resource as follows: map.resources :articles do |articles| articles.resources…
Dave Sims
  • 4,958
  • 3
  • 22
  • 26
107
votes
3 answers

Rails: Custom text for rails form_for label

I want to display a label in form_for:
<%= f.label :name %>
<%= f.text_field :name %>
This generates the label "Name", but I want it to be "Your Name". How can I change it?
Paul S.
  • 4,066
  • 9
  • 32
  • 51
83
votes
2 answers

Rails not editable text field

I have a form_for written in the following manner:
<%= location.label :city %> <%= location.text_field :city, :disabled=>true%>
<%= location.label :country %> <%= location.text_field…
Joe
  • 1,689
  • 3
  • 16
  • 24
64
votes
2 answers

Ruby on rails: singular resource and form_for

I want user to work with only one order connected to user's session. So I set singular resource for order routes.rb: resource :order views/orders/new.html.erb: <%= form_for @order do |f| %> ... <% end %> But when I open the new order page I get…
petRUShka
  • 9,231
  • 12
  • 54
  • 86
42
votes
3 answers

When using shallow routes, different routes require different form_for arguments

I'm using Simple Form here, but this is an issue with normal Rails forms, too. When using shallow routes, form_for needs different arguments depending in what context it's used. Example: For editing (http://localhost:3000/notes/2/edit),…
James
  • 2,436
  • 3
  • 38
  • 48
39
votes
3 answers

Change html form id generated by form_for rails 3.1

I have this form_for: <%= form_for [post, Comment.new,], :remote => true do |f| %> <%= f.text_area :content, :cols =>10, :rows => 1%> <% end %> <%= f.submit :class => "input_comment" %> That generate the next code html:
hyperrjas
  • 10,278
  • 22
  • 91
  • 188
31
votes
1 answer

Custom name for params hash from Rails form_for

Ordinarily, using form_for(@foo) means that on the back end of the form's action, you'll have the form data in params[:foo], but in my case I'd like to have a custom namespace applied to these params, i.e. params[:bar], not params[:foo]. I'm not…
JellicleCat
  • 23,907
  • 21
  • 96
  • 144
30
votes
3 answers

Nested resources in namespace form_for

Problem The form_for helper incorrectly determines the path to my nested resource inside of a namespace. The models in question are: Forum::Thread and Forum::Reply respectively, located in a subfolder called "forum" under my models directory. This…
user19302
23
votes
3 answers

Rails: Using form_for multiple times (DOM ids)

I would like to use the form_for helper multiple times for the same model in the same page. But the input fields use the same ID attribute (in the HTML), so clicking on the label of a field in another form will select the same input in the first…
iGEL
  • 13,729
  • 9
  • 53
  • 65
20
votes
3 answers

RoR differences between :url, :action, :method in form_for

There might be answers in documentation, but i don't seem to find good answers. So among the three :url, :action, :method, what are their differences when used in form_for in Rails?
sovanlandy
  • 1,655
  • 2
  • 19
  • 24
19
votes
3 answers

Form_for with :multipart => true spits out

I am trying to add an Avatar Upload field to my Profile Page, but as soon as I add the :html => {:multipart => true} to it, it spits out an syntax error. <%= form_for(@user), :html => { :multipart => true } do |f| %> <%= render…
Martin Lang
  • 355
  • 1
  • 3
  • 11
16
votes
2 answers

Rails 3: using non-Active Record objects with form_for

Is there any documentation, or advice?
Alex Zuzin
  • 193
  • 2
  • 9
16
votes
1 answer

Rails 4: fields_for in fields_for

I am learning RoR and i am trying to find how to set a fields_for in another one with has_one models like this: class Child < ActiveRecord::Base belongs_to :father accepts_nested_attributes_for :father end class Father < ActiveRecord::Base …
15
votes
4 answers

STI and form_for problem

I am using Single Table Inheritance for managing different types of projects. Models: class Project < ActiveRecord::Base end class SiteDesign < Project end class TechDesign < Project end Edit action from projects_controller: def edit @project…
ebsbk
  • 4,364
  • 3
  • 20
  • 29
1
2 3
61 62