New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails Blogger Tutorial - Strong Parameters #606

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

Comments

Projects
None yet
2 participants
@MrMaksimize
Copy link

MrMaksimize commented Jul 14, 2013

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

This comment has been minimized.

Copy link

MrMaksimize commented Jul 14, 2013

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

This comment has been minimized.

Copy link
Contributor

steveklabnik commented Jul 14, 2013

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

This comment has been minimized.

Copy link

MrMaksimize commented Jul 15, 2013

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

This comment has been minimized.

Copy link
Contributor

steveklabnik commented Jul 23, 2013

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