RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Holy cow, I was wondering *yesterday evening* when will you release a jQuery railscast, and voilà! Railscasts make Monday mornings enjoyable again :-)

Avatar

Thanks Ryan, I didn't realize it was so easy to use webrat on its own!

Avatar

even if we hide links using below code, any one can directly go to the url and access the page:

<% if permitted_to? :edit, @article %>
    <%= link_to "Edit", edit_article_path(@article) %> |
  <% end %>

what if guest goes and types
/articles/new
?

don't we also need to put the check in controller?

Avatar

I found a dark corner in declarative_authorization usage. If you defined a privilege in authorization_rules.rb:

  privilege :update, :includes => :edit

you can't just use:

  filter_access_to :update

in the controller definition when you really mean:

  filter_access_to [:edit, :update]

Avatar

Thanks Ryan! I just merged your smart code into my new project. It runs smoothly on my development machine, like always. But when staging on Heroku, the server emits errors showing that I have to convert `roles_mask' to integer before it will work as expected:

  ROLES.reject { |r| ((roles_mask.to_i || 0) & 2**ROLES.index(r)).zero? }

It's strange, and I don't know why. Since `roles_mask' is an integer field in the database, ActiveRecord could automatically detect its type and assign the value to an integer variable accordingly. Am I right or did I miss something?

Avatar

Thank you very, very much for this. I was stuck on forms for 5 hours today trying to do a multi-select on a has many through. When I couldn't figure it out I said "f it. Railscasts will have a better solution". 30 minutes later, everything works perfectly. Thank you very much!

Robert

Avatar

I have a really important question to ask about RUBY ON RAILS. I'm a newbe that has been doing research on ROR for about 3 mouths or so and my question is, how do you style an application? I've seen a number of screencast but not one seems to address this issue, which is a shame because its something every programmer will have to do. I would like it if you could cover this topic in a screencast to help newbes like myself understand how to make things look better on a presentation bases. Thanks.

Avatar

use tidy_ffi, works like a charm

Avatar

Hello.
For those that are having the :password no method error.

Check out your migrations. Verify you don't misspelled the columns.

Cheers!

Avatar

I need graph gem.what should i use for graph.Please tell me which gem is available for graph.
Thanks,
Manish Kumar

Avatar

Never mind. I found the answer at http://wiki.macromates.com/Troubleshooting/SnowLeopard

I guess I should always look a bit more...

Avatar

This may or may not have been covered in a previous episode, but when I try to run the Ruby on Rails test script in TextMate, I get the error shown below. The script runs using 'ruby nokogiri_test.rb'. I am running Snow Leopard. Thoughts?

Error:
/Applications/TextMate.app/Contents/SharedSupport/Support/lib/io.rb:38:in `exhaust': undefined method `first' for nil:NilClass (NoMethodError) from /Applications/TextMate.app/Contents/SharedSupport/Support/lib/tm/process.rb:227:in `run' from /Applications/TextMate.app/Contents/SharedSupport/Support/lib/tm/executor.rb:211:in `parse_version' from /Applications/TextMate.app/Contents/SharedSupport/Support/lib/tm/executor.rb:98:in `run' from /Applications/TextMate.app/Contents/SharedSupport/Bundles/Ruby.tmbundle/Support/RubyMate/run_script.rb:93

Avatar

Reporting spam does really worth/work?

I would like to be a moderator or a spam reporter on chief here on railscasts :)

As someone said before, you're my role model,
thanks.

Avatar

I have a Problem with observed_field

if i want to update, it is only
possible if the Controller will not
be filtered, otherwise it says that
the method isn't found. Well, i added
the method tho the authorization-file.

Strange thing... can anyone help?

Avatar

Scrapi works good but there is a problem with UTF-8 characters, e.g. german "Umlaute" like ö, ä, ü.
Scrapi messes them up.
In the scrape cheat sheet there is a hint that one can call:
myscraper=scraper.scrape(uri, :parse_options)
where :parse_options should have something to do with tidy, i.e. scrapi should be able to deal with utf-8 characters.
Has anybody done this ?
I don't see how to use :parse_options.
Please post an example of working code which uses those :parse_options! Thanks.

Avatar

Anyone help with:

Q1: What do you have to do in all your other controllers & models (i.e. besides user & user_session)? Do you need to put something like "before_filter :require_user" at the beginning of other controllers? (or should something like this go in application_controller to get blanket coverage)

Q2: Can anyone confirm what config exactly is required to make the one time password (persistence_token) work?

thanks

Avatar

You might want to look at vtd-xml, the latest and most advanced xml processing model, far better than DOM or SAX

<a href="http://vtd-xml.sf.net">vtd-xml</a>

Avatar

That's a nice demonstration and Gemcutter looks really neat. I also noticed that you can use "gem tumble" multiple times to cycle between different configurations.

Avatar

When I went from webrat 0.6.0 to 0.5.3 I didn't get

the undefined method `css_search' for Webrat::XML:Module (NoMethodError) (eval):2:in `table_at' error.

I saw a post on the IRC channel saying they removed css_search from webrat???
http://irclogger.com/cucumber/2009-10-28#1256763887

cheers

Avatar

Great screencast Ryan!(as always). Btw, since there is more spam comments than actual useful ones, do you mind adding captcha support? We certainly won't mind it :)

Avatar

Hello,

what kind of Plugin is it, to wrtie "Role.all" and you get lovely formattet answer?

Avatar

hey, Ryan,

 Searchlogic V2 is out.
 Is this for V2? If not, could you please show one for V2?
 Would be nice to see how you go abouts setting up routing for the search resource :) thanks

Avatar

Hi Ryan

Thanks for all the great screencasts.

You make it look effortless!

D

Avatar

@Espen: Here you go - http://www.rubyinside.com/ruby-xml-performance-benchmarks-1641.html

Avatar

When I took out the model reference stuff (@articles = Article.find(:all) ) I ended up with no data. Any reason why filter_resource_access wouldn't be doing what it's supposed to?

Thanks for the very helpful show.

Evan

Avatar

Hey Ryan,

I'm using a hosting company (Dreamhost) that doesn't allow me running daemons in the background all the time. Eventually the just stop the processes. What would my options be to run actionmailer in the background without a daemon running?

thanks so much!

Avatar

Here is the same Walmart scraper rewritten with my nifty "Scraper" class:
http://gist.github.com/246309

http://github.com/mislav/scraper

Avatar

Very nice, thank you Ryan.

Good job with the comment spam too.

Avatar

Great 'cast! Relevant as ever. SelectorGadget is an awesome tool, thanks a bunch for highlighting that.

Avatar

Hello Ryan,
Amazing screen cast, You always cover the items I am working on next!
Keep up the great work!

Avatar

Ryan, I have posted this before but it may have gotten lost among all the spam. Since spam really disables a fruitful conversation (or even just reading) of this little forum, I think you have to attack the problem seriously. Here is my funny but possibly quite powerful solution:

I have a solution for the spam. Since most of us know at least a bit about rails (otherwise we wouldn't give a rat's ... about the Railscasts), as a simple question in addition to Captcha for example:

Fill in the blank:

validates_xxxxx_of :firstname, :lastname

or something more funny (and political LOL):

validates_xxxxx_xxx :smartpresidents, :in => "George W. Bush"

(...exclusion of that is LOL)

Avatar

Would this work for getting football statistics or is there a better way to do that?

Thanks!!

Avatar

I don't think I'll be using ScreenScraping any time soon in my apps, however SelectorGadget looks like a great tool which may come in handy for me at some point.

Thanks Ryan.

Avatar

Great episode. This looks cleaner than ScrAPI.

Btw I didn't have to provide libxml path when installing nokogiri. gem install nokogiri worked like a charm. I'm using Windows with cygwin environment.

Avatar

Hi Ryan,

Great screencast and I look forward to the next episode featuring Mechanize as most of us will likely need the ability to interact with the website being scraped.

That said, I've opted against Mechanize in favor of Celerity given Mechanize's lack of support for Javascript in today's jQuery/Prototype, etc world.

Sure there are generally workarounds to bypass the Javascript (fun) and Watir (though I prefer Celerity's faceless browser). Perhaps highlighting this weakness of Mechanize in your screencast will encourage the addition of such support...that and better documentation. :-)

Avatar

Why you didn't use your gem can can?

Avatar

Anyone done a performance comparison of Nokogiri vs Hpricot?

Avatar

Hi, Ryan! Thank you for one more great screencast. I'd like to translate you casts to russian. If you agree, please, contact me, course I tried, but got just this:
Delivery to the following recipient failed permanently:

    feedback@railscasts.com

Technical details of permanent failure:
The recipient server did not accept our requests to connect. [mx1.sub4.homie.mail.dreamhost.com.railscasts.com. (0): Destination address required]
[mx2.sub4.homie.mail.dreamhost.com.railscasts.com. (0): Destination address required]

Avatar

I got the "password confirmation is too short problem"
and corrected it by adding

attr_accessible :password, :password_confirmation

in the user model.

Is this the correct solution?

Avatar

@Jamie - sure, it helps to ask for permission. That's what I do at least :)

@Ryan - thanks for another great episode!

Avatar

Great, another one library for doing it,
very like this stuff, thanks!

Avatar

After some problems setting up nokogiri it is really awesome. XML parsing and screen scraping as simple as possible. And fast!

Avatar

Love the idea of scraping website's. Can't wait till next week!

Avatar

Great!, thanks a lot!

Avatar

These sort of casts really interest me as I am learning about something I had no idea about before.

However I am sure I have a very good use for bitmasks now in my upcoming app.

Thanks! :)

Avatar

Hey Ryan, just a small improvement to your roles= method:

Wrap roles up to allow non-array assignment

self.roles_mask = ([*roles] & ROLES).map { |r| 2**ROLES.index(r) }.sum

That way you can just pass user.roles = 'admin'

Avatar

Ryan,

Great presentation. One question, how do you manage the version numbering with a VCS like svn, hg, git etc.? I'm just exploring Mecurial now, but with svn, I'd cp trunk to a tag. If I want to bump a version, there is no automated way to sync that with jeweler, I suspect.

I am currently looking into amp, which lets you customize a Mecurial setup. Maybe there is something that can be done there.

Amp would be a great idea for another Railscast... once it matures a little.

Ed