原创作者: hideto
阅读:1424次
评论:0条
更新时间:2011-05-26
我们习惯与one-action-per-request,但是我们(特别是初学者)很容易被controller里的new(),create(),edit()和update()这些方法弄晕。
其实我们可以用一个方法来代替them all:
这证明了Ruby语言的强大和灵活
但和RESTful Rails Development不好合并,以为后者是对应到上述不同的方法的
其实我们可以用一个方法来代替them all:
def edit @recipe = Recipe.find_by_id(params[:id]) || Recipe.new if request.post? @recipe.attributes = params[:recipe] redirect_to :main_url and return if @recipe.save end end
这证明了Ruby语言的强大和灵活
但和RESTful Rails Development不好合并,以为后者是对应到上述不同的方法的
评论 共 0 条 请登录后发表评论