开发者

form_for syntax problem

开发者 https://www.devze.com 2023-03-01 16:08 出处:网络
I need to generate something like <% fo开发者_开发问答rm_for [@user, @name], :html => { :multipart => true } do |f| %>

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

精彩评论

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