aboutsummaryrefslogtreecommitdiffstats
path: root/guides/code/getting_started/app/controllers/posts_controller.rb
diff options
context:
space:
mode:
authorAnkit Gupta <ankit.gupta8898@gmail.com>2013-07-07 13:43:24 +0100
committerAnkit Gupta <ankit.gupta8898@gmail.com>2013-07-07 15:59:18 +0100
commit53f12b073cc238757431708e6730e60b10b4d5fe (patch)
tree536bbd430941638f3d0d0a2ba60550ba457620c5 /guides/code/getting_started/app/controllers/posts_controller.rb
parenta7ff577383dcf1b36d075b70713f614c598b2430 (diff)
downloadrails-53f12b073cc238757431708e6730e60b10b4d5fe.tar.gz
rails-53f12b073cc238757431708e6730e60b10b4d5fe.tar.bz2
rails-53f12b073cc238757431708e6730e60b10b4d5fe.zip
Refactored strong paramters usage and updated Gemfile.lock with Rails 4
Diffstat (limited to 'guides/code/getting_started/app/controllers/posts_controller.rb')
-rw-r--r--guides/code/getting_started/app/controllers/posts_controller.rb10
1 files changed, 8 insertions, 2 deletions
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