开发者

Rails Screencast - Completely stuck on "fields_for"

i am following this simple tutorial and i followed all the steps... but the browser simply doesn't show me anything i put inside the fields_for tag.

<%= form_for :activity, :url => activities_path do |f| %>

    <% if @activity.errors.any? %>
      <div id="error_explanation">
        <h2><%= pluralize(@activity.errors.count, "error") %> prohibited this activity from being saved:</h2>

        <ul>
        <% @activity.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
        </ul>开发者_如何学JAVA
      </div>
    <% end %>

  <div class="field">
    <%= f.label "Foto" %><br />
    <%= f.text_field :photo %>
  </div>
  <div class="field">
    <%= f.label "Foto per la home" %><br />
    <%= f.text_field :photoHome %>
  </div>

    <% for info in @activity.infos %>

    This is rendered<br>

      <% fields_for "activity[info_attributes][]", info do |info_form| %>

    This is not rendered<br>

        <p>
          Titolo: <%= info_form.text_field :title %>
        </p>
        <p>
          Descrizione: <%= info_form.text_field :description %>
        </p>
      <% end %>
    <% end %>
    <p><%= submit_tag "Create activity" %></p>

<% end %>

The above code result is this:

Rails Screencast - Completely stuck on "fields_for"

What am i missing?


Rails is sometimes (well ok, often) a bit confusing in which helpers want a <% vs which helpers want <%=. Try

<%= fields_for "activity[info_attributes][]", info do |info_form| %>

The tutorial you're following doesn't, but that's from 2007, and in Rails 3 this was changed. Current documentation on fields_for is here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜