0

我有两个资源:推荐和评分。

推荐型号:

class Recommendation < ActiveRecord::Base
  has_many :ratings
  accepts_nested_attributes_for :ratings
end

评级模型:

class Rating < ActiveRecord::Base  
  belongs_to :recommendation
end

建议控制器:

class RecommendationsController < ApplicationController

  def index
    @product = Product.find(params["product_id"])
    @recommendations = Recommendation.find(:all, :joins => :products, :conditions => ["product_id = ?", (params["product_id"])])
    @recommendation = Recommendation.new
    @rating = Rating.new
  end

  def create
    #need to find_or_create new rating based on recommendation_id 
  end  

end

推荐指数:

<div id ="prods_container">
  <%= form_for @recommendation do |f| %>
    <%= f.fields_for @rating do |r| %>
      <% @recommendations.each do |rec| %>
        <%= rec.title %>
        <div id="rec_note_text"><%= r.text_field :notes %></div>
      <% end %>
      <%= f.submit %>
    <% end %>
  <% end %>
</div>

我正在尝试为每个“推荐”对象添加一个注释字段,我需要在我的create操作/推荐控制器中更新评级表。如何将正确的 ID 传递给我的控制器以实现此目的?

4

0 回答 0