RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Great screencast again.
The table_at does not seem to work anymore here.

Avatar

this is an awesome tutorial. But when i try it out, i encounter some problem.

It simply won't save the questions and survey name to the database after i added field_for in my view. Anyone else having that issue?

If I remove it, survey name are saved

Avatar

Sorry, forgot my email address on last post...

I am getting the same "is not recognized by the 'identify' command" error. I have found that if I take away the :styles of has_attached_file, I can successfully post the image. I would obviously like to be able to resize the image, though. Can anyone help?

Avatar

I am getting the same "is not recognized by the 'identify' command" error. I have found that if I take away the :styles of has_attached_file, I can successfully post the image. I would obviously like to be able to resize the image, though. Can anyone help?

Avatar

oh and I'm on windows 7 x64

Avatar

I can't get gems to update on ruby 1.3.7 or 1.9.1 - I always get this error:

ERROR: While executing gem ... (Errno::EEXIST)
    File exists - C:

Can't find anything online to fix it.

Avatar

I get an error when from rake setup and rake gems:install:

rake aborted!
undefined method '>=' for nil:NilClass
C:/Ruby/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2383:in 'raw_load_rakefile'

and suggestions?

Avatar

Thank you - this is a great webcast!

One idea for improvement is to support counter cache. Say in your example above in the Product model you had:
  belongs_to :category, :counter_cache => true

then it would be nice if while adding products to a category the counter would be incremented automatically.

Avatar

Another question:

How do you implement a check box that checks all the check boxes (if you know what I mean!)?

Cheers

Avatar

In reply to myself, I checked out Episode 165

Result!

Avatar

@George: I'll take the liberty of saving Ryan a response. "To sport" is a verb used for precisely this purpose. It means "to wear or display" (something) and is often used as a synonym for "have" when the writer wishes to make the writing feel more active. It also has a positive, energetic connotation, making it well-suited to describing new features of a product, service, or fashion.

Avatar

Hi Ryan,
Thank you for a great tutorial. Keep it up.

p.s. I noticed what I think might be a typo in the episode description.
"Rails 3 sports" should be "Rails 3 supports".

Avatar

Hi Ryan,

Thanks again for the great screencast! Question about the Ability class, you are doing a check for role?, but what if there's a many to many user-role relationship? Does cancan know to check all the roles? or should Ability.rb be updated to user.roles?

I keep getting undefined method `role?' for #<User:0x1032be9a0>

my guess is it's because the user has many roles so user.role? really should be user.roles?, but that doesn't work either.

I'm going to dig into the cancan code and see what i can dig up.

Thanks,
John

Avatar

cannot :index, User

why does this block all users

if I have added

can :manage, :all if user.role == "admin"

Admin user should be able to view index, right?

http://stackoverflow.com/users/283179

moderator edit: Jul 13, 2011 [ link ]

Avatar

You have to set the top-level DIV id attribute to "home" (just giving it class of "current" is not enough). This is valid for the Beta 2 version of jqtouch. I saw the infinite loop issue on Jaunty with FF 3.0.x... that was painful to track down given that there are very few good examples for jqtouch (even the oreilly iphone book with the jqtouch example doesn't show the id attribute).

Avatar

Great screencast! At first glance, I figured the changes were merely for the purposes of being more DRY, but now I see how powerful the benefit of lazy loading can be!

Avatar

Great screen-cast, very helpful details on what's to come from Rails 3 in terms of routing. You got a very clear voice, looking forward to more screen-casts.

Avatar

Doesn't having all your application js code in a single file become hard to maintain? Furthermore, this comment related js will be in other views that are unrelated and do not use this code, isn't that an issue as well?

Avatar

@Ryan, I believe you will find the "not" operator for booleans will work for all databases.

If that was not the case, queries that use "is not null" would never work, surely?

Avatar

Great cast, as always! I'm wondering if Ryan or anyone has built the user-end of the survey...take survey/show results, etc...?

Avatar

@Tobias, I heard of a :defaults option you can supply for default values, but I could not get this to work. If nothing else it's pretty easy to handle default values on the controller side.

@Jose, right, shallow routes are in the works I believe.

Avatar

The API is not complete though. Shallow routes are missing, for instance.

Avatar

The new routing is looking really sexy, like everything I've seen of Rails 3 so far.

It's gonna be another good year for us rubyists ^^

Avatar

Hey Ryan, I owe you so much! Concerning page caching and dynamic content I read about ESI which sounds like a cool method. I will mix your way of hiding the admin links with some ESI partials with Easy-esi: http://github.com/grosser/easy_esi. Maybe ESI (though not really new) is worth an episode?

Cheers, Val

Avatar

Good screencast as usual...
I'm new to rails, and now I can understand about this great framework coz your screencast.
Thanks Ryan...

Since I watch and followed your screencast, I didn't see screencast about Chat Application with Rails. Would you please to make screencast about it (e.g. with XMPP4R or Juggernaut) correct me if I'm wrong)...
Thanks before

Avatar

I think that you have to edit the routes.rb file in the config folder so that it ...

Avatar

Another great episode! I like Monday mornings ;-)

@Ryan:
One question to the :year, :month, :day variables. Is it possible to set standard values for those that were not provided - or do you have to do this in the controller method itself?

Thanks and keep up the great work!
Tobias

Avatar

If you are having trouble with your app being unable to start because of activerecord/database.yml related errors, make sure to put this

config.frameworks -= [ :active_record]

in your environment.rb

Avatar

NICE AUTHENTICATION HACKING PROGRAM

Avatar

John, You cannot upload files via Ajax, Use an hidden iframe instead. Or just leave the idea of Remote form with file upload.

Good luck.

Avatar

once CanCan is added to a project,

there are problems with my user edit link.

<%= link_to "Edit Profile", edit_user_path (:current) %>

error
Couldn't find User with ID=current

Anybody know any fix's?

Avatar

Greate stuff! Really simple to use, loved it! thanks a lot!

Avatar

@LW, yep, I've run into the same issue.

I also ran into an issue on Rails 3 where the AJAX requests load the full HTML page, but don't replace the whole page. So you end up with

<html>
  ...
  <body>
    <html>...</html>
  </body>
</html>

Which is obviously wrong. So looks like this screencast might be a bit out of date or didn't take that into account :-(

Avatar

@0x4a6f4672, @Ryan: Ruby 1.9 has introduced slip intermediate operations
into the middle of a call chain, so to prevent the train wrecks you can use tap() method, eg:
Article.first.comments.first.tap {|x| puts x}.user.name

Avatar

Thanks Ryan -- really useful.

How would the javascript function change in the case of several child model objects to be enumerated?

So, to extend on your example, what if Survey had models: photo_of_respondent, questions, survey_worker, etc.?

Thanks, Grar

Avatar

@Senthil http://pastie.org/797950

To those using that reference I must correct it. Instead of doing the initiation of a new and then save, follow this pattern.

Role.create!(:role => "admin")
Role.create!(:role => "user")

Way faster, and saves you the typing ;)

Avatar

The following commit seems to indicate the database migrations are no longer needed.

http://github.com/rails/open_id_authentication/commit/ee5be2f26c37049f6c37e113627a34c1ef6d35cd

Avatar

A very good article, I will always come in.

Avatar

Hello,

First, thanks for posting this video it has helped me much.

However, I am stuck at the point where I can´t seem to get the APP_CONFIG[:paypal_secret] to get returned to the application and can´t figure out why.

I downloaded the source code and tested the app... but the problem remains.. I cant validate the transaction with the secret.

Hope you can help me.

Thanks.

Avatar

@Omar, using "not hidden" will work in SQLite3 but is not database agnostic. I prefer to use SQL queries which can be used in other SQL databases if need be.

@Michael, it appears that the hash syntax you mentioned is still supported.

@Alex, I'm working on upgrading nifty generators to Rails 3, yes.

@James, you're right that Rails 3 is not yet stable and should not be used in production. However I highly recommend everyone give it a try now. Start a small project with Rails 3 or try branching an existing project and upgrading to get an idea of what is involved and report anything that breaks.

Right now a lot of the work needs to be done by the community. One of the biggest roadblocks to upgrading is unsupported plugins. If you want the plugins you use to work with Rails 3 the best thing to do is try it now to see what breaks and report any issues to the developers.

Avatar

Ryan - Great Cast once again!

A Question: How would you implement a "mass edit" facility?

What I mean to say is: say you had an attribute which you want to set to the same thing for ALL rows selected on the front form. How do you do this with a single control?

Cheers

Avatar

@James

Rails 3.0 works great as it is right now. Not something you would use in production for sure. But playing with it to learn what's new is great. And Bundler handles dependencies great with Git.

Only downside is the lack of ported plugins. But they are getting there. I'm already using MongoMapper and Formtastic together. Paperclip has a Rails3-branch that was forked too, which works properly with Rails 3.0beta. So it's getting there =)!

Avatar

hmm ... tried doing this but for some reason my sort is not getting saved to the database in the position column ...

I have manually entered in page positions and they do sort properly but the position just doesnt get updated .... Any help would be fantastic.

Avatar

Is it just me... or when I double-click on one of the resulting values, I get the values twice in the text field, sometimes half of the 2nd one ?!?! Weird!

Chris

Avatar

@James think of it this way; you can spend 10 minutes watching the screencast and have a good idea of what is going on with Rails3, without wasting hours of your time messing with it.

I am still using 2.3.5 too, but I still want to know about 3.0 :)

Avatar

Hi Ryan,

Congrats on 200 episodes.

I am trying to follow the Railscast on WinXP, with a fresh install of 1.9.1 and rails 3 beta.

When I try to start the server with "rails server" in the root directory of the topscore app I get:

C:/Ruby19/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/bin/rails:2: command not found: C:/topscore/script/rails
C:/Ruby19/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/bin/rails:2:in `exec': No such file or directory - C:/topscore/script/rails (Errno::ENOENT) from C:/Ruby19/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta/bin/rails:2:
in `<top (required)>'
        from C:/Ruby19/bin/rails:19:in `load'
        from C:/Ruby19/bin/rails:19:in `<main>'

I think this is saying that the 'rails' script in the topscore/scripts directory cannot be found, the file does exist. Although it has no file extention.

Any one got any idea why it's not working?