From 7438e2fa83b7a9185f4814ddd0f7eab2183c142d Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Tue, 25 Jun 2013 19:06:15 -0300 Subject: Fix another "error_explanation" css class in guides [ci skip] --- guides/code/getting_started/app/views/posts/_form.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'guides/code/getting_started/app') diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb index c9fb74af9c..f2f83585e1 100644 --- a/guides/code/getting_started/app/views/posts/_form.html.erb +++ b/guides/code/getting_started/app/views/posts/_form.html.erb @@ -1,6 +1,6 @@ <%= form_for @post do |f| %> <% if @post.errors.any? %> -
+

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

    @@ -14,12 +14,12 @@ <%= f.label :title %>
    <%= f.text_field :title %>

    - +

    <%= f.label :text %>
    <%= f.text_area :text %>

    - +

    <%= f.submit %>

    -- cgit v1.2.3 From 53f12b073cc238757431708e6730e60b10b4d5fe Mon Sep 17 00:00:00 2001 From: Ankit Gupta Date: Sun, 7 Jul 2013 13:43:24 +0100 Subject: Refactored strong paramters usage and updated Gemfile.lock with Rails 4 --- .../getting_started/app/controllers/comments_controller.rb | 8 +++++++- .../code/getting_started/app/controllers/posts_controller.rb | 10 ++++++++-- guides/code/getting_started/app/views/welcome/index.html.erb | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'guides/code/getting_started/app') diff --git a/guides/code/getting_started/app/controllers/comments_controller.rb b/guides/code/getting_started/app/controllers/comments_controller.rb index 0e3d2a6dde..b2d9bcdf7f 100644 --- a/guides/code/getting_started/app/controllers/comments_controller.rb +++ b/guides/code/getting_started/app/controllers/comments_controller.rb @@ -4,7 +4,7 @@ class CommentsController < ApplicationController def create @post = Post.find(params[:post_id]) - @comment = @post.comments.create(params[:comment].permit(:commenter, :body)) + @comment = @post.comments.create(comment_params) redirect_to post_path(@post) end @@ -14,4 +14,10 @@ class CommentsController < ApplicationController @comment.destroy redirect_to post_path(@post) end + + private + + def comment_params + params.require(:comment).permit(:commenter, :body) + end end diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb index 6aa1409170..02689ad67b 100644 --- a/guides/code/getting_started/app/controllers/posts_controller.rb +++ b/guides/code/getting_started/app/controllers/posts_controller.rb @@ -17,7 +17,7 @@ class PostsController < ApplicationController def update @post = Post.find(params[:id]) - if @post.update(params[:post].permit(:title, :text)) + if @post.update(post_params) redirect_to action: :show, id: @post.id else render 'edit' @@ -29,7 +29,7 @@ class PostsController < ApplicationController end def create - @post = Post.new(params[:post].permit(:title, :text)) + @post = Post.new(post_params) if @post.save redirect_to action: :show, id: @post.id @@ -44,4 +44,10 @@ class PostsController < ApplicationController redirect_to action: :index end + + private + + def post_params + params.require(:post).permit(:title, :text) + end end diff --git a/guides/code/getting_started/app/views/welcome/index.html.erb b/guides/code/getting_started/app/views/welcome/index.html.erb index 738e12d7dc..56be8dd3cc 100644 --- a/guides/code/getting_started/app/views/welcome/index.html.erb +++ b/guides/code/getting_started/app/views/welcome/index.html.erb @@ -1,3 +1,4 @@

    Hello, Rails!

    <%= link_to "My Blog", controller: "posts" %> +<%= link_to "New Post", new_post_path %> -- cgit v1.2.3