从事这一示范协会类任务。 基本协会在发挥作用,但与“类别”网页的观点无关。
类别 产出应为(类别)
- Dish-ID
- Dish-Title
- Restaurant-Title <= HOW DO I GET THIS VALUE?
rules: - dish belongs to one category - same dish can be in multiple restaurants
class Category < ActiveRecord::Base
has_many :dishes
end
class Dish < ActiveRecord::Base
belongs_to :category
end
class Restaurant < ActiveRecord::Base
has_and_belongs_to_many :dishes
end
class DishRestaurant < ActiveRecord::Base
has_many :restaurants
has_many :dishes
end
主计长
def show
@category = Category.find(params[:id])
@dishes = @category.dishes
// RESTAURANT TITLE ??
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @category }
end
Category View: <%= debug @dishes %>
任何方面都会有所帮助。
thanks
pete