RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

@vlad, I just edited the title in the session information panel (command-i).

Avatar

@Mike, the routing error you get will be a 404 error in production mode, so I think that fits rather well. Of course you can also check if no product was found and have it behave however you need it to.

@RainChen, not exactly sure what you mean. If you're using Apache you can still use mod-rewrite where you need it. Or perhaps you're looking for a custom route instead?

map.foo "/foo", :controller => 'bar', :action => 'foo'

Avatar

to answer my own question, i eventually found this: http://xanana.ucsc.edu/xtal/iterm_tab_customization.html

i don't think i'll be using it though, seems too hackish and does some weird things when sshing.

Avatar

Can Rails perform static resources rewrite as apache mod-rewrite?

btw,you voice is nice.

-RainChen

Avatar

anyone know how to show the process name as the tab title in iterm like in the video?

Avatar

Per my last comment, I'm actually using movies and their titles instead of products ;)

Mike

Avatar

Ryan,

This is pretty cool, a "shortcut" search instead of waiting for a form to load/ submit etc ... just like typical unix command line stuff ;)

However, one thing you didn't show in your railscast is what happens if you try to find a product that doesn't exist .
Or maybe I've messed something up on my setup.

If I try "http://lh:3000/gl" for example, and none of my products start with "gl" I get a routing error

http://pastie.caboo.se/77040

Mike

Avatar

Upgrading to ruby 1.8.6 from 1.8.5 has fixed the problem.

Mike

Avatar

@Mike, hmm, I'm not sure what the problem is. Perhaps the gem is being required too early. You might want to try this: http://pastie.caboo.se/76786

Avatar

Ryan,

On Win XP : I'm using InstantRails:
- Ruby 1.8.5
- Rails 1.2.3
- Active Record 1.15.3

I installed ruby-debug and it works fine in Mongrel but when I load a console (ruby script\console), I get the following errors : http://pastie.caboo.se/76785

Avatar

Often I just want to assign something to a variable, but I don't want to see tons of output, e.g. actors = Actor.find_all.

I discovered that I can eliminate the (large) output by appending a "dummy" command that returns nil or something short like 1.

E.g.
actors = Actor.find_all ; 1
or
actors = Actor.find_all ; actors.size

Mike
Mike

Avatar

Great job Ryan! Loved the last 3 Railscasts...

Idea for your list of Railscasts: how to work with different database types and different server types?

Avatar

As always another good tutorial. I always like it when I see another video available. Although I am falling a little behind in trying to keep up :)

Thanks Ryan

Avatar

@Swami, LOL.

@Geoff, that's awesome. I didn't know that. Looks like adding 1.year or 1.month is smarter as well. It no longer does a simple convert to 365 or 30 days. I can't wait until 2.0 is released!

@darryl, good point. I had trouble coming up with an example for using ruby-debug since most situations are more complex than what can be covered in a short screencast.

Avatar

Great job as always. It's good to have another tool to use. but...

In practice, this method should have gone through unit testing, in fact even before the method was completed. Also if you use .to_date on the method parameter, you would get around any type issues.

(i know this was not the goal of this sreen cast, but i'm just saying...)

Avatar

Great tutorial, thanks!

Btw, Date.today + 10.days has been fixed in edge.

Avatar

Great job as usual Ryan.

I like the 'acting' when, with your tone of voice, you pretend to be baffled by the mistake, and then, you feel relieved to have discovered the mistake.

Avatar

@Pratik, cool, thanks. Didn't know about this.

Avatar

Hey Ryan,

Great cast. Just a little correction about what you said.

You said it may not be possible to use it with Apache/Lighty. Well, in theory it is.

You can just put following in your development.rb :

require 'ruby-debug'
Debugger.start_remote

Then from shell, do 'rdebug -c'.

Thanks!

Avatar

@Ryan,

I thought that might have been the problem, so I upgraded - am now on 1.2 but the issue is still there.

Avatar

Heya Ryan, great screencast, much better than what I would have done, and you are welcome for the pointer :)

for more info, you can also type entire expressions into the debugger, like:

p Foo.find(:all, :conditions => { blah })

Basically, in the debugger, anything you could puts from the console, you can see.

Looking forward to your next great episode!

Avatar

@Kev, what version of Rails are you using? This requires Rails 1.2. If you are using an older version then it won't work.

Avatar

Hi,

Really good screen casts but I am also having a problem with setting up the sessions_path and home_path variables

I have set up the the routes.rb file as specified in the video, but I get this error:

undefined method `first' for :sessions:Symbol

if i comment out the map.resources line
then I get the undefined method or variable sessions_path error.

Any help appreciated

Kev

Avatar

@Luke, I went ahead and changed the feed so it will display all episodes. You should be able to download all episodes through iTunes in a day or so.

Avatar

Thanks Ryan, anybody knew how to upload file using attachment_fu plugin.Ryan, will you make one?

Avatar

I try to use plugins inside and outside of rails so putting the reference to ActiveRecord::Base at the bottom of the plugin/lib file rather than in the init.rb is a bit more portable.

Also, I agree with Nicolas about using either send or respond_to? rather than read/write_attribute. this de-couples the plugin from the database and makes it easier to unit test.

thanks for your great work!

Avatar

@xajler, I have done some episodes on authentication and authorization in the past. You can see them here.

http://railscasts.com/tags/9

@Mahmoud, sorry to disappoint. I considered touching on the "rescue" statement, but this is more about Ruby than Rails. Maybe it will work though.

Avatar

@Mahmoud Actually the ruby rescue system can be used in that way basically the rescue_action_in_public just gives you a chance to catch exceptions outside for all actioncontroller code

you can do a rescue block for specific errors or all error within a single action or in a begin-rescue-end style block for a specific portion of code

so

<code>
  def some_action
    ..code..
    begin
      .. something that goes wrong..
    rescue
      .. to the rescue!..
    ensure
      .. Always do this!..
    end
  end

</code>

or

<code>
  def some_other_action
    .. stuff that might go wrong ..
  rescue SomeSpecific::ClassOfError
    .. rescue for that case ..
  rescue Exception => e
    .. General error of any sort ..
    .. e is the class of exception ..
  end
</code>

Avatar

The exception-notifier plugin is a REALLY great way to be notified of exceptions (...) in production mode.

http://dev.rubyonrails.org/svn/rails/plugins/exception_notification/

Avatar

Yes you can. The full exception can always be found in the variable $!

Avatar

Thanks for a great railscasts. I would like to know if there is a way to mail the "rails private error page" to someone when something goes wrong, and show the user another message. It should be possible to do in the rescure_action_in_pulic, if I knew how to render the rails exception page...

Cheers!

Avatar

Oh! i clicked in @Nico Orellana to visit the website.. but it seems that users are not very pleased to add each time the http:// :)

Avatar

I'm a little bit disappointed about this episode. I found it useful to know about such methods, but it wasn't what i expected! in fact, I thought that it will be sth like try.. catch.. in other languages to keep the users in the default layout.

Avatar

Hello Ryan, you're making a terrific work over railscasts and the rails community, haha, is getting difficult to follow u in each episode (time!! you know! :()... cheers from Santiago de Chile.

Avatar

Thanks, very good cast like all before. Will you make one about authorization and authentication?

Avatar

The escape key is what I used. It will look at the rest of the document and do some basic auto-completion.

Avatar

so simple and clear, thanks!

by the way, Ryan, how do you toggle words so quickly in textmate?

for example when you was printing drop_table 'categories_products' in the migration.

there was no hotkey displayed :).

Avatar

Ryan,

Great episode. I have question concerning the controller. I see the pattern of always having a new -> create, edit -> update method.. But then I see some repeated code in the new and the create (like typically find the object by ID). Could use call the new method to do the setup of the default data and override them from the create method? Or is there a better way to refactor that?

Avatar

@Ryan: I think a Railscast on :has_many :through with polymorphic associations would be really nice. I find lots of documentation on :has_many :through, and on polymorphism. But, hardly anything with them together. Also, if you do this, could you please make sure to go through the controller workflow (ie. what gets created and when). Again, this is an area that is almost never mentioned. The focus is almost always on the model. Also, could the has_many_polymorphs plugin be the answer?

Avatar

@JackVandaL, thanks, fixed. I gotta learn to copy and paste the code instead of retyping it. :/

Avatar

Sorry two other things:
- submit_tag needs a closing %>
- it's ":collection" not ":collections"
:)

Avatar

@Rob

current_user.tasks.update_all(["completed_at=?", Time.now], :id => params[:task_ids])
end

Avatar

I'm having trouble installing the will_paginate plugin using <code>script/plugin install svn://errtheblog.com/svn/plugins/classic_pagination</code>.

I keep getting a timeout error saying subversion can't connect to host 'errtheblog.com'. Anyone have any ideas? Is anyone else having this problem?

Avatar

If we were to do this with multiple users, how can we first ensure that the task IDs belong to the current logged in user (in case someone edits the HTML and puts in a task ID that doesn't belong to them)?

Avatar

Great job Ryan. One thing your code snippet has "form_for" not "form_tag".

Avatar

Thanks again Ryan for you great work.

@Leeky - It is actually the 'name' of the field that is referenced (and not the id) for submission. It is common practice (as many rails helpers do) to call the id and name the same. Im sure you can used the name as described in this screencast and use the dom_id plugin (http://topfunky.net/svn/plugins/dom_id/) to give your forms unique ids. This would be helpful for validation and for giving this task ajaxy goodness.

Avatar

Another great railscast as usual. One thing that I'd like to know is if there's a way to make the checkboxes each have a different ID in the HTML code, and still have the form work?

I noticed in the example that every checkbox has the same ID, which is invalid, as ID's are meant to be unique within a XHTML document.

Avatar

@Markus,

I've pointed out the link to submit bug reports to in my previous comment. And the error you're seeing *can't* be right because Rails 1.2 uses alias_method_chain internally all over the place! If you keep seeing the error, submit a proper report with more information. Thanks