Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

RubyonRails 4.0 incompatible with rake db:migrate command ?

I'm running Ruby 2.0.0 and I installed it correctly. Just loaded up a gem 'devise' and as I tried to migrate my database changes, it wouldn't work:

$ rake db:migrate rake aborted! attr_accessible is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add protected_attributes to your Gemfile to use old one.

Then, following another Stackoverflow post, they recommended installing Bundler. I did that successfully and got this:

$ bundle exec rake db:migrate rake aborted! attr_accessible is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add protected_attributes to your Gemfile to use old one.

Is anyone up to the challenge to help?

Howdy Flex

attr_accessible was a hack that got round a security problem (related to mass-assignment). It's a way to filter params being posted to your application at the model layer.

In Rails 4 the code to support the attr_accessible's hack has been removed from the main rails gem and put into a another gem for those who want this functionality and this is the error message you are seeing.

The Rails 4 way is to have the filtering done at the controller layer by what has become know as Strong Params. In the controllers you'll see something like this:

def episode_params
  params.require(:episode).permit(:description, :name)
end

This is the Rails 4 strong params bit and in the above code this permits only description and name params in rails 3 the model would have had attr_accessible :description, :name instead.

I would recommend removing all attr_accessible code from the model layer and replace it with the new Rails 4 filtering at the controller layer.

I'm not aware of any treehouse videos on Rails 4 but this Railscast video is free to watch and (I believe) covers this topic.

Rich

Thank you so much Rich! I tried uninstalling rails and then tried reinstalling Ruby 3.2 but that wasn't working out as I imagined. It's amazing how complex these set up processes can be. I will definitely dive into the Railscast video you posted. Thanks for all of your help. It means a lot.

Yeah there's a lot to take on. No, getting around that.

If you are following the tutorial you want Ruby 1.9.3 ish and Rails 3.2 ish

The latest rails is 4.0 (it was released last week) and the latest Ruby is 2.0. There isn't a big difference between Ruby 1.9 and 2.0 (but best to stay on 1.9) but as you've seen you can only follow the tutorial on Rails 3.2.

Make sure that when you are in the terminal and in the root of your treehouse project and you type: ruby -v you are seeing 1.9.3. You want to make sure that in the root of the project the Gemfile has the line: gem 'rails', '~>3.2.0' or something similar and not gem 'rails', '4.0.0'. In which case you're good to go.

You won't need the railscast to complete this tutorial but it's a great resource for further study.

Good luck.

Rich

1 Answer

Jason Seifer
STAFF
Jason Seifer
Treehouse Guest Teacher

Try locking rails at version 3.2.13 by putting the following in your Gemfile:

gem "rails", "3.2.13"
gem "devise", "2.2.4"

You should be able to following along with the videos that way. Sorry for the trouble! A new version of rails was just released and we haven't updated the videos yet.

Here was my way around it, works like a charm, though I did it "the lazy way". I've been enjoying the challenge running into rails 4 problems and solving them.

https://teamtreehouse.com/forum/strongparameters-and-treebook

Thank you for your help Jason and Daniel! Turns out my ruby version 2.0 was locked in to using rails 4.0. I had met a guy who worked at github that spent 10 minutes trying to solve it. I wish it was as simple as just editing the gem file. I am now set up to use ruby 2.0 with rails 3.2.13. Hopefully the devise install will work out.

Keep smiling Jason! Cracks me up every time haha

Good times,

If you want to take a peek at my github profile, all my code is rails 4 compatible and functional on Heroku. It won't look exactly like treebook (just having some fun improvising), but the controllers/models/tests are all the same.

Cheers

Flex Philips Jason Seifer Yea, really. If it was only that easy... Dropped in those two gems and got incompatible version of this (fix), than that(fix), than this(fix) and on and on. Hours in about ready to give up. I am not as fortunate to have a github aficionado off hand.

Bundler could not find compatible versions for gem "activesupport": In snapshot (Gemfile.lock): activesupport (4.0.0)

In Gemfile: rails (= 3.2.13) ruby depends on activesupport (= 3.2.13) ruby

Bundler could not find compatible versions for gem "activesupport": In snapshot (Gemfile.lock): activesupport (4.0.0)

In Gemfile: rails (= 3.2.13) ruby depends on activesupport (= 3.2.13) ruby

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Sorry about that! You may want to start over with a Rails 3.2.13 app.

Jason Seifer I'm confused, is that not what I just said that I did and is what I had all those problems with? I have to say that your explanations on how to troubleshoot are lacking any real depth. Perhaps if you could provide a bit more instruction that would be helpful.