不确定我的form_for有什么问题

时间:2013-08-12 16:07:07

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

在一部分餐饮食品的布局中,我有以下代码:

  <tr class="food food-tr-<%= meal_food.id %>">
    <td><%= meal_food.name  %></td>
    <td>
      <% form_for :meal_food, meal_food, url: { controller: "foods", action: "update" }, html: { class: "meal_food_servings-#{meal_food.id}" } do |f| %>
        <%= f.number_field :servings %>
      <% end %>

    </td>
    <td><%= pluralize(meal_food.serving_size, meal_food.measure_type) %></td>
    <td><%= meal_food.fat    %></td>
    <td><%= meal_food.carbs  %></td>
    <td><%= meal_food.protien %> </td>
    <td><%= link_to "x", food_path(meal_food.id), method: :delete, remote: true %> </td>
  </tr>

在第二个td单元格中,我尝试渲染一个提交食物更新操作的小表单。

我一直在运行的错误是这个只是尝试渲染这些表格所在的用餐节目页面。

wrong number of arguments (3 for 2)

我按照此处的导轨指南示例http://guides.rubyonrails.org/v2.3.11/form_helpers.html#binding-a-form-to-an-object

当我把

<%= meal_food %> 

输出meal_food对象参考。所以我不确定那里的问题是否存在。

谢谢!

---------- Routes.rb

      mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'

      resources :status_updates do 
        collection do 
          delete :delete_all
        end
      end

      resources :meals  
      resources :foods do
        collection do
          get :search
        end
      end


      devise_for :users, :controllers => { :registrations => "registrations" }

      root to: 'static_pages#home'
      match '/faq', to: 'static_pages#faq'
      match '/contact', to: 'static_pages#contact'

1 个答案:

答案 0 :(得分:1)

试试这个:

<%= form_for meal_food, url: food_url(meal_food.id) html: { class: "meal_food_servings-#{meal_food.id}" } do |f| %>