Ondra
Ondra

Reputation: 3180

form_for syntax problem

I need to generate something like

<% form_for [@user, @name], :html => { :multipart => true } do |f| %>

in my rails template, but this syntax is not allowed. What is a right syntax for this situation. Thanks!

Upvotes: 1

Views: 712

Answers (2)

fl00r
fl00r

Reputation: 83680

your syntax is ok. You've just forgotten equal = sign:

<%= form_for [@user, @name], :html => { :multipart => true } do |f| %>

and also you need to manage your routes as well

resources :users do
  resources :names
end

And you need to specify @user and @name in your controller action:

def new
  @user = User.new
  @name = @user.names.new
end

Upvotes: 2

Naren Sisodiya
Naren Sisodiya

Reputation: 7288

Assuming the @name is attribute of @user, then following code will work.

<% form_for @user, :html => { :multipart => true } do |f| %>
<%= f.text_field :name %>
<% end %>

see more about form_for

Upvotes: 0

Related Questions