Une autre question de débutant.has_many méthode de construction, Rails
Objectif: chaque ingrédient peut avoir zéro ou plusieurs conversions d'unités liées. Je veux mettre un lien pour créer une nouvelle conversion d'unité sur la page qui montre un ingrédient spécifique. Je n'arrive pas à le faire fonctionner.
Modèle Ingrédients:
class Ingredient < ActiveRecord::Base
belongs_to :unit
has_many :unit_conversion
end
Unité Modèle de conversion:
class UnitConversion < ActiveRecord::Base
belongs_to :Ingredient
end
Controller Conversion (pour nouvelle)
def new
@ingredient = Ingredient.all
@unit_conversion = @ingredient.unit_conversions.build(params[:unit_conversion])
if @unit_conversion.save then
redirect_to ingredient_unit_conversion_url(@ingredient, @comment)
else
render :action => "new"
end
end
Routes pertinentes:
map.resources :ingredients, :has_many => :unit_conversions
Afficher des ingrédients Lien:
<%= link_to 'Add Unit Conversion', new_ingredient_unit_conversion_path(@ingredient) %>
Ceci est l'erreur:
NoMethodError in Unit conversionsController#new
undefined method `unit_conversions' for #<Array:0x3fdf920>
RAILS_ROOT: C:/Users/joan/dh
Application Trace | Framework Trace | Full Trace
C:/Users/joan/dh/app/controllers/unit_conversions_controller.rb:14:in `new'
Aide! Je suis tout mélangé à ce sujet.