RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Ryan,

Can more than one attribute be combined / concatenated ?

e.g. :
Something like ... (this doesn't work) :

ActorNames = Actor.find(:all).collect(&:last_name + ' ' + &:first_name)

.. neither does :

ActorNames = Actor.find(:all).collect(&:last_name,&:first_name)

Mike

Avatar

These continue to be a great help! This is one of the best ones yet, thanks Ryan!

Avatar

Found it, I think:
http://railsdocumentation.org/api/

Avatar

This is my first time at this. I spent some time looking at the docs on api.rubyonrails.org coming up with improvements only to find that when I checked out rails from svn, the docs there were nothing like the docs on the site. I suppose it's because the code is under development but I also couldn't find patches documenting the changes.

Is there some place online to view the "live" up-to-date documentation?

I also couldn't get the activerecord 'rake test_mysql' tests to pass on three separate systems.

Perhaps it's not meant to be. :(...

Avatar

Jamis Buck posted about a nice script/console trick that allows you to toggle on ActiveRecord log output -- handy when you want to see the generated sql from an AR query: http://weblog.jamisbuck.org/2007/1/31/more-on-watching-activerecord

Avatar

@art: I'm not sure if it's the same for the ruby logger but in with log4j using the logger meant that you could send any text to /dev/null so that it didn't take up any CPU time in production. Using puts would remove that benefit unless you'd launch your server and redirect all output to /dev/null explicitely.

Avatar

Concatonating strings like that will cause an error if middle_initial returns nil, which is why I chose to use string interpolation.

Avatar

Display it where? Do you mean out put it as a string to the log or something? I don't think that's possible with define_method.

Avatar

@Ekolguy, I don't think it's documented in the API. I learned about it from other sites which talk about customizing Rails.

@art, I don't recommend using puts. This will cause problems when you switch to other web servers (apache or lighty). It messes up the HTTP headers which can cause strange bugs.

Avatar

Thanks Ryan for the quick reply. And yes, you were right. I needed to add in values for my datetimes into my fixtures.

Avatar

I don't know about Mongrel but with Webrick you can use "puts" instead of logger.debug to display whatever you like in the Webrick log. This works in plugins, views, controllers, models...I think everywhere =)

Avatar

Thanks for the great screencast! One question though:

config.active_record.colorize_logging = false

There is no way one could find colorize_logging method of active record in API (or is it not a method? Anyway how to find it?). Some time ago colored logging was annoying me under windows and I just couldn't find a way to disable it. (before watching your screeny of course:))

These kind of small things are still keeping me away from diving into rails because I'm afraid of not finding what I'm looking for :(

Any advices?
Thanks!

Avatar

i was curious about the interpolation of middle_name in the full_name method. why use interpolation there if 'middle_initial' (which i assume is a column in the db) would work too? is it b/c <pre>middle_initial + " " unless middle_initial.nil?</pre> wouldn't work? or would it?
this site is amazing, btw!

Avatar

I didn't phrase that too well.

I mean display the code that define_method generates.

Mike

Avatar

Ryan,
Is there a way to display the generated code from define_method ?

Mike

Avatar

Cool, I'll check them both out - thanks Ryan

Avatar

Martin,

Curl can send information via a POST request, so that wouldn't stop a malicious user. Ryan's suggestion is definitely worth looking into...

Avatar

so, why not just build a poll app with Rmagic or sth else.
I think many guys will meet the image process app soon or later.

Avatar

@Phillip, that looks like it will work. If it doesn't you may want to post about this on railsforum.com.

Avatar

@schlick, make sure each of your fixtures has the time column specified in it. It sounds like the time is returning "nil" which will result in the error you are receiving. If you still can't get it to work I recommend you post on railsforum.com about this.

Avatar

Nifty piece of advice and I have already implemented it in my project however it seems to cause my functional tests to fail. Is there anything extra/special that needs to be done in other for it to work in my tests. I keep getting a 'wrong number of parameters' error for to_s.

Avatar

I wanted to reference the documentation because it took me quite a while to find this. http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001024

That's all about the with_scope method in ActiveRecord::Base. Hopefully someone else finds it useful for me to link it here.

Avatar

Ryan, yes, I am in the iTunes Music Store. In my iTunes I see all 1-55 listed except for 20-23. Given you're seeing them all I'm guessing now that I may have inadvertently deleted those from my iTunes (I did already view them once).

So an iTunes question for you or anyone -- is there a good way to restore a deleted iTunes entry?

Avatar

Hey Ryan great ca$t, I was wondering if this was the bes appraoach to update a div with something like this:
<% @brands.each do |brand| %>
   <%= link_to_remote(image_tag(brand.filename),:url => {:action => 'show_description', :id => brand}, :class => "description") %>
<%- end %>

pretty much passing the :id of brand to a partial how would one go about that?

Avatar

@rs and ryan,
it seems to me that having multiple <link.../> tags is like having multiple <script /> tags in the head. is there some rule that says multiple script tags are ok, but link tags for css should be in one file? eric meyer has 8 stylesheet links on his homepage (as of today). i think he knows what he's doing vis-a-vis css.

it's a fantastic little railscast, btw. these little tricks make dev so much easier and smarter. thanks for doing this! you're a mensch.

Avatar

Great tutorial Ryan! This one really helped me out. Keep up the high quality work.

Avatar

@Brian, hmm, those episodes are showing up for me in iTunes Music Store. Is that where you're looking?

Avatar

@crayz, yeah, the partial refactoring is questionable. I showed it mainly for variety to cover the different refactoring techniques.

The "title" method was covered in a previous episode: http://railscasts.com/episodes/30.

I have covered concat and capture in a previous episode as well: http://railscasts.com/episodes/40

Avatar

I would disagree with the final refactoring of the loop into a partial/collection. It doesn't really slim your code at all, and will make future alterations more of a hassle as you switch between the two files. Good stuff though

I'd be interested in a review of more advanced concepts like using concat, capture, content_for - and when you might use those in conjunction with or instead of helper methods - e.g. the <% title "blog" %> at the top, how was that implemented?

Avatar

It appears the feed is missing episodes 20-23. If you can, can you add those to the iTunes feed?

Avatar

Ryan,

These are really great!

One suggestion: Many people primarily consume your videocasts via iTunes and may only visit the home page.

It took me many weeks before I found out you had code examples in the permalinks. I'd encourage you to have a "Read more..." or "Read Show Notes/Code..." link from each post in the main index.

Just a thought, keep it up!

Avatar

Nope, it only works on very simple method calls which don't take an argument. Anything more complicated and you will need to use the full block.

Avatar

Maybe a stupid question but is it possible to use Symbol to_proc even for methods which need an argument?

Avatar

Great stuff. Just what I needed when I needed it... Keep up the spot on tutorials!

Avatar

Sorry about the downtime guys. I guess that's the price to pay for the cheap Dreamhost bandwidth. :/

Avatar

Really nice this post, but could you create a screencast about test unites in views? Thanks!

Avatar

Fantastic example! Love the episodes. Please keep them coming :-)

Avatar

Download is working again!

Avatar

Congratulations on the popularity of these. I really like them. I couldn't download them either, until just now :) Had to wait for a break in the queue I guess.

Avatar

media.railscasts.com seems to be down :(

Avatar

Actually I can't download any episode, strange.

Hoping for a quick fix :)

Avatar

Both links are not works for me

Avatar

Can't download this episode, too.

Avatar

Couldn't download file :(

Avatar

Download link doesn't seem to be working for me.

Avatar

nice and neat!~

Avatar

My fav screencast along with the other 53 :)

Avatar

@Bobby, that's a good suggestion, but I don't know if I will ever get around to implementing it. For now please email feedback [at] railscasts [dot] com if you wish to make a suggestion.

I'm planning to add a poll to the site in the near future, so you can vote on what you want to see. :)

Avatar

Hey, Ryan - I would like to propose having a Railscast Wishlist feature; this is becoming one of the best resources for Rails learning, I'm sure you could get a lot of ideas for screencasts from your avid "fans" out there!

Bobby

Avatar

ryan, i meant automatically.