【发布时间】:2011-05-21 20:22:39
【问题描述】:
我正在 Rails 中创建一个食谱管理器(谁不是他们的第一个应用程序?),这是我的布局:
Ingredient belongs to Recipe
Recipe has many Ingredients
制作反映这种关系的表格的最佳方法是什么?我在想一个输入,当一个输入被填满时,会创建另一个输入,所以成分表的末尾总是有“一个更多”。
创建 UI 后,模型和控制器的结构会是什么样子?现在我有脚手架控制器create 方法:
def create
@recipe = Recipe.new(params[:recipe])
respond_to do |format|
if @recipe.save
format.html { redirect_to(recipes_path, :notice => 'You made a new recipe!') }
format.xml { render :xml => @recipe, :status => :created, :location => @recipe }
else
format.html { render :action => "new" }
format.xml { render :xml => @recipe.errors, :status => :unprocessable_entity }
end
end
end
params[:recipe] 是否应该只是一个嵌套更深的对象/哈希/字典,包含一系列成分或其他东西?
感谢您在此提供的任何指导。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 model controller has-many