开发者

Rails 3 only need to edit one field from a loop

Order has_many :items and Accepts Nested Attributes for.

Want to loop through the items in the Order form, but only need the item.qty field to be editable. Would like to display the other fields as normal <%= item.name %>, etc.

I know that I can use readonly and disable or even clean it up with css, but开发者_如何学C wondering if there is a better way.

order form looks like this.

<%= form_for [current_company, @order] do |f| %>
 ...
  <%= f.fields_for :items do |item| %>
    <%= render :partial => 'item', :locals => { :item => item } %>
  <% end %>
 ...
<% end %>

item partial looks like this.

<tr class="item">
  <td><%= item.text_field :name %></td>
  <td><%= item.text_field :short_description %></td>
  <td><%= item.text_field :price %></td>
  <td><%= item.text_field :qty %></td>
  <td> <%= item.text_field :full_price %> </td>
</tr>


<%= item.object.name %>
<%= item.object.description %>

etc

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜