开发者

simple_form_for not showing fields

开发者 https://www.devze.com 2023-01-29 07:10 出处:网络
I have a model (Project), in the \'new\' action I have this code <h1>Create new project</h1>

I have a model (Project), in the 'new' action I have this code

<h1>Create new project</h1>
<% simple_form_for @project, :url => create_project_path  do |project_form| %>
<%= project_form.error_messages %>
<ul>
    <% project_form.input :name %>
    <% project_form.input :subdomain %>

    <% project_form.input :allow_email_report_client %>
    <% project_form.input :allow_email_post_client %>

    <% project_form.submit %>
</ul>
   <% end%>

the controller code is simple I have a load_and_authorize_resource (using CanCan) and the action code is this

def new
@project = Project.new
end

now, I do get a tag rendered but no fields inside this form

I have the exact sa开发者_C百科me thing for Account model and there all of the fields are shown with no problem.

does anyone have an idea what is the problem?


Ah! You're missing the = signs in your fields:

<%= project_form.input :name %>
<%= project_form.input :subdomain %>
....

Without the =, the code within the <% %> will run, but there will be no output.

Also, good to know: in Rails 2.x you do not need the = for the form_for (Rails 3, however does need the =)


Make sure your new action looks like this:

def new
  @project = Project.new
end
0

精彩评论

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