开发者

form_for syntax problem

I need to generate something like

<% fo开发者_开发问答rm_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!


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜