From b44b3932438a5fc794e9d6711bc76c2f3f35aa8f Mon Sep 17 00:00:00 2001 From: Yoshiyuki Hirano Date: Mon, 14 Aug 2017 22:09:36 +0900 Subject: Fix debugging rails application [ci skip] --- guides/source/debugging_rails_applications.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'guides/source') diff --git a/guides/source/debugging_rails_applications.md b/guides/source/debugging_rails_applications.md index 58aab774b3..7ea3646c30 100644 --- a/guides/source/debugging_rails_applications.md +++ b/guides/source/debugging_rails_applications.md @@ -162,20 +162,24 @@ class ArticlesController < ApplicationController # ... def create - @article = Article.new(params[:article]) + @article = Article.new(article_params) logger.debug "New article: #{@article.attributes.inspect}" logger.debug "Article should be valid: #{@article.valid?}" if @article.save - flash[:notice] = 'Article was successfully created.' logger.debug "The article was saved and now the user is going to be redirected..." - redirect_to(@article) + redirect_to @article, notice: 'Article was successfully created.' else - render action: "new" + render :new end end # ... + + private + def article_params + params.require(:article).permit(:title, :body, :published) + end end ``` @@ -542,7 +546,7 @@ command later in this guide). 9 => 10 respond_to do |format| 11 format.html # index.html.erb - 12 format.json { render json: @articles } + 12 format.json { render json: @articles } 13 end 14 end 15 -- cgit v1.2.3