2011-07-01 24 views
1

私は少し簡素化しようとしているテーブルを持っています。私の見解では(このビューはすでに部分(_recipe_ingredient.html.erbです)、私は部分的にレンダリングが動作していない次のコードを、持っている:Rails - 別の部分の編集部分を部分的にレンダリングする

<tr> 
    <td><%= recipe_ingredient.ingredient.name %></td> 
    <td><%= recipe_ingredient.ingredient.weight1*recipe_ingredient.quantity %></td> 
    <td><%= recipe_ingredient.ingredient.description1 %></td> 
    <td><%= recipe_ingredient.quantity %></td> 
    <td><%= render(:partial => 'recipe_ingredients/edit', :locals => 
    {:recipe_ingredient=> recipe_ingredient}) %></td> 
    <td><%= link_to 'Remove', recipe_ingredient, :confirm => 'Remove ingredient from 
    recipe?', :method => :delete %></td> 
</tr> 

以前に、私はとしてrecipe_ingredientを編集するのlink_toを使用していました(うまく働いている)以下の、しかし私は、ユーザーが編集し、別のページに移動していないたいと思います - 代わりに私は、フォームがテーブルの一部になりたい:

<td><%= link_to 'Edit Quantity', edit_recipe_ingredient_path(recipe_ingredient) %></td> 

編集新しい非(どの部分作業コード呼び出し)は次のようになります。

<h1>Editing recipe_ingredient</h1> 
<%= render 'recipe_ingredients/form', :recipe_ingredient => @recipe_ingredient %> 

などの標準的なフォーム部分ルックス:それはのlink_toを使用して動作しますなぜ

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

     <ul> 
     <% @recipe_ingredient.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= recipe_ingredient.label :quantity %><br /> 
    <%= recipe_ingredient.number_field :quantity %> 
    </div> 
    <div class="actions"> 
    <%= recipe_ingredient.submit %> 
    </div> 
<% end %> 

は主に、私は困惑しているが、私は単に部分をレンダリングすることはできません。私が得ているエラーは、部分的なフォームの最初の行にundefined method `model_name' for NilClass:Classです。

フォームの部分で@recipe_ingredientをオフにしてみましたが、どちらも機能しません。

ご協力いただきありがとうございます。

答えて

0

あなたのアクションで@recipe_ingredientを使ってオブジェクトを作成するだけです。編集アクションだと思います。

@recipe_ingredient = RecipeIngredient.find_by_id(params[:id) 

これはうまくいきます。

+0

が既にコントローラにあります。 – Lev

関連する問題