Rails Blogger Tutorial - Strong Parameters #606

Closed
MrMaksimize opened this Issue Jul 14, 2013 · 4 comments

Projects

None yet

2 participants

@MrMaksimize

So I ran into a problem following http://tutorials.jumpstartlab.com/projects/blogger.html#i1:-form-based-workflow

The attr_accessible doesn't work anymore.

So I read up on it here:

http://rubysource.com/rails-4-quick-look-strong-parameters/

Looks like in Rails 4, this has been abstracted to a gem.

So I added

config.active_record.whitelist_attributes = true to config/application.rb

Added to Gemfile.

gem 'strong_parameters' 

Ran bundle in the commandline to install the gem.

This gem adds the ability allow certain users to create / update certain fields within your model.

So -- in my articles model I added

include ActiveModel::ForbiddenAttributesProtection

and in my articles_controller I added a method called article_params:

def article_params
  params[:article].permt(:title, :body)
end

and my create method now looks like this:

def create
  @article = Article.new(article_params)
  @article.save
  redirect_to article_path(@article)
end

Wasn't sure if you guys were looking for updates to this tutorial for Rails 4, but figured I'd throw it out there.

I sure learned something new :)

@MrMaksimize

Figured I'd update instead of edit :)

Looks like in Rails 4 it's already included, so adding it into the gem file just causes errors.

So the part about adding it to Gemfile is wrong

@steveklabnik
Contributor

The tutorial is explicitly for rails 3.2 right now. I want to update it for 4, but have not yet.

On Sun, Jul 14, 2013 at 12:48 AM, Maksim Pecherskiy
notifications@github.com wrote:

Figured I'd update instead of edit :)
Looks like in Rails 4 it's already included, so adding it into the gem file just causes errors.

So the part about adding it to Gemfile is wrong

Reply to this email directly or view it on GitHub:
#606 (comment)

@MrMaksimize

Ah makes sense.. I think I may have just missed it somewhere.

Hey but I still learned something :)

I think it's worth closing then?

@steveklabnik
Contributor

I've updated this now, should be fine. Thanks for bringing it to my attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment