我试图跟随sandi metz'每种方法五行规则, 你对转动基本控制器的好方法有什么想法吗? 并将方法更新为五行代码。
def create
@article = @blog.articles.build(article_params)
if @article.save
flash[:success] = "Article saved!"
redirect_to blog_article_path(@blog, @article)
else
flash.now[:error] = "Unable to save article. Kindly correct the errors before trying again."
render :new
end
end
def update
if @article.update_attributes(article_params)
flash[:success] = "Article updated!"
redirect_to blog_article_path(@article.blog, @article)
else
flash.now[:error] = "Unable to update article. Kindly check the errors and correct them before trying again."
render :edit
end
end
任何建议,评论&建议将非常感谢:D
答案 0 :(得分:1)
您的代码看起来很棒,此模板后面还有rails scaffolding。此外,如果从考虑中删除if-else条件语句,则您的方法遵循每个方法规则的五行。