RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

@Fredrik

You're absolutely right. I have no idea why I didn't use create at the time.

Avatar

Great cast, it made me think and is an elegant solution. I wish you made more casts like this - it is the ones I enjoy the most.

Avatar

Thank You, Ryan, for another great screencast.

Does anyone know where there isn't a where! method to do part of what dynamicdelegator can do ?

Avatar

Nice technique, but I think it's wasted in the example. A few characters saved, but a whole lot of readability lost. The code goes from 5 lines to many more over 2 files.

Codec is unhappy on VLC/SMPlayer (Ubuntu). Works fine in Totem (same as last week).

Avatar

For the record, link_to_function, being generic even if not unobtrusive, has been restored to Rails 3.

Avatar

How would I do this sort of thing, only NOT as a SELECT?

For instance, I have a request form - the user selects from Categories (Hardware, Software, Media, etc)

Based on that selection, the next select box is populated with its corresponding Products (PC, Monitor, Printer, etc)

Based on that selection, I want the product.description to display below the selected product.

HELP!??!? and THANK YOU! :)

Avatar

Thanks for this episode Ryan but I have to agree with M. Hasenstein and iain. I dont think there is much you gain from that. The readability decreases dramatically. Everybody could have changed the first lines of code but the last ones? I am not so sure about that. Not everthing must be DRY.

Anyway I am looking forward to the next cast!

Best regards
Tobias

Avatar

@iain I'd agree if the site were called Rubycasts. Returning is still an expressive pattern for rails enthusiasts.

Avatar

Hi Ryan, do u know a working way to autheticate Rails3 over openid or twitter?

Avatar

Aaaaawesome!
Having classes of validations is really a step forward.

Avatar

Has anyone used Squirrel? For Rails 2 projects I like it to do conditional logic in my queries. Also searchlogic does cool stuff with named_scoped. For conditional logic I do like Squirrel better.

Avatar

Nice screencast as usual. I would suggest using a config.action_mailer.smtp_settings statement in config/environments/*.rb instead of old the ActionMailer::Base.smtp_settings. Makes managing different ActionMailer configs for different environments easier.

Avatar

Clever little class, but I think a name like AutomaticChainer might have better conveyed what it does.

Avatar

I don't really know everything, but shouldn't you use Arel entirely when doing where predicates, that is, something like :

products.where(products.table[:name].matches("%" + params[:name] + "%")) if params[:name]

Avatar

Great, thank you Ryan. Just what I was waiting for!

CodeOfficer: Will look into that returning() method, thank you.

Avatar

What a coincidence, I made a blogpost about the same technique a week ago: http://iain.nl/2010/04/viewtranslator-a-dynamic-dispatcher/

I agree with Micael Hasenstein: it's something interesting in gems to provide pretty APIs, but not as end code itself. Though ultimately one part of your code is the API for that other part.

@CodeOfficer: I think returning is not the right way to go. I think using tap is better, since it is included in Ruby itself (since 1.8.7).

Avatar

(Again) issues with the video file when viewing with VLC (platform: Linux), same as last time. Used to work fine before you started experimenting with codecs ;-(

On the subject: Yes, you can do lots of tricks with Ruby (or any modern language). But what's the point? You don't gain much (in this example you don't get ANYTHING you didn't already have) but loose readability and maintainability. This is even more important in large(r) projects with lots of people - one can complain about the stupidity of the univerye as much as one likes, but "average programmers" simply won't EVER be as good as good ones, and you cannot afford hiring only top-experts for everything.

IMHO the place for such (and much worse) trickery is inside frameworks such as rails, where only experts work and where the benefit is greatest because it multiplies, but not in "end programmer" application code.

Avatar

Your DynamicDelegator pattern is a great place to use Rails returning() method as well.

returning(scoped) do |model|
model.method if condition?
end

Avatar

Hi Ryan,

Doesn't this really call for mutator methods in ARel (sorry for being lazy and not checking the rails-core)?

Would that be a cleaner solution?

Thanks,
Swanand

Avatar

Awesome, I'm excited to see all the benefits of the new Active Record query interface, especially now that `scope` is a first class citizen.

Avatar

Nevermind, I figured it out. It is just standard action mailer settings.

Avatar

re custom_action.js.erb

I find it really easy, just match add it in your routes

all you need to do is add ".:format" on the end, so that rails can then use that in the respond_to/with e.g.

match '/contact_auto_search.:format' => 'contacts#contact_auto_search'

so I can now goto www.mysite.com/contact_auto_search.js and it responds to the js.erb file....

Avatar

Instead of "gem install authlogic-oid", better use
script/plugin install git://github.com/mreinsch/authlogic_openid.git
to avoid errors. Remove 'config.gem "authlogic-oid' in your environment.rb.
It works with official updated open_id_authentication plugin

Avatar

I am not really impressed by kurtlar vadisi pusu. Sevilen dizi izle kvp son bolum hemen izle.

Avatar

When running the rails update checker, I found i did have to provide an = for the each method, such as <%= @comments.each do |comment| %>

To those who want to see rails 2.3.x, rails 3 will most likely go into full release later this year. Personally, id rather start seeing this stuff now, to keep up with the curve.

On another note, anyone else in converting an app rails 3 have trouble using resources stored in the public folder such as stylesheets?

Avatar

Thank for this very nice railscast. I have one little critisism however. I think is it better to send a different secret with every paypal checkout. It's not hard to do and much more secure.

Avatar

Anyone know how to change the email server settings in Devise?

Avatar

Is this now outdated? I am using Rails 2.3.5 and if I use the @article.comments.build I get an error message noting that there is a "undefined method 'build' for nil:NilClass .....

Avatar

Hi Ryan, and thank you so much for your great screencasts!
How does it come that when trying to render a js.erb template, rails3 (beta3) renders it with a text/html content-type (instead of text/javascript)? Am I missing something?
Thanks

Avatar

Hi Ryan,

great video, as usual.

I have a question, not directly related to ERB, but more to blocks. Why use the '&' sign when passing a block as an argument?

Avatar

this is the first time video file doesn't play nice. i mean, there were freezed frames all over the cast.

don't know if it is my linux machine (ubuntu 9.10) or the player (vlc).

so, i want to know if you (Ryan) made it in a different way (different kind of codec may be). that way, i could see other alternatives.

thanks.

Avatar

Great casts, thank you.

I have a question about testing and devise, do you have any links to help simulate a login in functional tests.

Avatar

Nice cast, I am going to try it out. Very useful.

Avatar

accepts_nested_attributes_for

How the hell do you do it with devise??

Avatar

Good video, one thing that might trip people up is that in the after_create method inside the payment_notification model the cart was not able to be found, it always returned as nil for me so the whole process would fail since it couldn't update the attribute.

To fix this I just defined a cart variable and find the cart by id using the params[:invoice] as we set this in the user model at the start. All worked well then.

Avatar

Thank you, very helpful. I'd like to review a similar cast about Cassandra with Rails.

Avatar

i have done everything in this tutorial up to adding the load_and_authorize_resource line to my controller, which causes this error:
undefined local variable or method `load_and_authorize_resource' for GameController:Class

if i only include CanCan in my ability.rb file then I don't see how it is included into the app unless I include the ability.rb file or tell it to load somewhere

Avatar

Hey Ryan,

thanks a lot for this episode.
Some time ago I searched for a clever solution and ended up with formtastic in combination with validation reflection. Would you prefer formtastic over this more barebone approach with less abstraction?
For me it is important to get going fast and to have maintainable code I can adjust if I need to.

Kind regards
Bijan

Avatar

Works under OSX 10.5 with movist.
Works under linux with kaffeine qt4, it doesn't work with smplayer or mplayer.

Avatar

And yet another great screencast!

I love how I can relive the discussions we had back when I was implementing this. For instance, seeing the JS which uses the current time as a random id :)

Thanks again for the great work Ryan!

Avatar

on logout call this in java script function
document.execCommand("ClearAuthenticationCache");

to clear the cache of the browser

Avatar

Hey Ryan, great screencast! Didn't know it existed until just now :)

In the beginning of the screencast you say there isn't much documentation on creating the views, but there is in fact some in the fields_for docs: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001605

You might want to add that link to the list of links.

Cheers

Avatar

The paperclip works on ubuntu but on windows it gives an some error.

the error is
 " There were problems with the following fields:
Avatar C:/DOCUME~1/ozone/LOCALS~1/Temp/Water lilies,2700,0.jpg is not
recognized by the 'identify' command.
 Avatar C:/DOCUME~1/ozone/LOCALS~1/Temp/Water lilies,2700,0.jpg is not
recognized by the 'identify' command "

any idea ??
i'm almost stuck here

thanks

Avatar

Hey rbates, thank you for your useful and awesome casts! Ryan, PLEASE, can you "Build an entire application over a series of screencasts" with Rails 3, where you can cover all other sub-topics like this validation and other devise and etc. Please, do not neglect this comment and make me and people who want to see you build entire apps happy. I would even pay to watch those. Thanks!

Avatar

If mail is not formatted properly, then the asterisks '*' is rendered between two div's.

Is there a simple way to move '*' into the first div?

<div class="fieldWithErrors"><label for="user_email">Email</label></div>*<br />
    <div class="fieldWithErrors"><input id="user_email" name="user[email]" size="30" type="text" value="x" /></div>

Avatar

Here is my simple RoR plugin for custom error template:

http://github.com/kelso/render_errors

Avatar

I have the same "riddle" issue as klumsyBird and gordon and Theokie. Sphinx compiled on an Arch Linux machine.

Also installed riddle gem, with no success. Any other Sphinx configuration needed (maybe in /etc/sphinx/)? Any ideas ?

Avatar

Thanks for the summary Ryan. I was the author of "Sexy Validations", you can see my original writeup here: http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/

Avatar

What would we do without you?

Over the last few episodes I have been convinced that I should be heading in the RoR 3 direction sooner rather than later.

A big 'thank you' Ryan.

Avatar

All new projects in ubernetics will be developed in Rails 3, all this rails 3 series railscasts help me to take this decision.. thanks Ryan!! Rails 3 here we go!!!!