RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Thanks for the info Ryan! I am glad that in later railscasts the example code is available for download. For those who are trying to get this to work today, you can download example code from my google code repo at:

https://gone-cat-open-source-software.googlecode.com/svn/tags/herbs-test-railscast-75

A couple of differences:
-- changed the application concept a little to fit what I am trying to build. The structure is almost identical but I changed the names of the models.
-- replaced prototype with jQuery so the javascript is a little different from what you find in the cast.
-- this example code was build on rails 2.3.2.

Avatar

Hi.

I'm trying to test the renderer class but I can't figure out how what to send as "template" when I initiate an instance in my unit test.

For example one of my helpers has:
BoxesRenderer.new( @box, self )
with works perfectly.

But what to substitute "self" with in my unit tests?

Here is my code: http://pastie.org/478963

Avatar

Hi

I understand how to implement roles on the entire site, but how would you break this down even further, to an account level for example?

I have an application that hold accounts. Each account can have multiple users with multiple roles and each user could belong to multiple accounts, again, with differing roles. An editor of one account may be the owner of another, for example.

I'm struggling to see how I can check to see if the currently logged in user is in a particular role for the account that they are trying to access.

So far I have tried using a Privileges table that holds a user_id, role_id and account_id, but I can't find a way to find out if the current user within the current account belongs to a certain role.

Confused and probably making it worse for myself...

Thanks for the great post.

Avatar

I have a question. I need to set up recurring job which can be send any minute of the day. I need to load rails environment every minute as cron job is running every minute. Which is the best way to do this ? Cron/Daemon or Starling ?

Avatar

@Daan -- see if the code at http://gist.github.com/111459 works for you.

If not, install Firefox and the excellent Firebug add-on. Then enable the javascript console -- you can monitor what is sent, what is received, headers, everything. For even better deep inspection install the TamperData plugin -- you can pause and modify data as it enters and leaves the browser.

Avatar

I had a bug with this approach on Internet Explorer. My remote form submissions were processed correctly on the server. However, rather than execute the returned callback script I was getting a "Security Error - File Download" and apprised that IE didn't know what to do with a 'text/javascript' file.

If you're fighting this, here's what I did.

In my case I've found out that IE doesn't set the accept headers correctly, so you SHOULD request a file with the right extension (.js, probably). In the railscast, Ryan, you allude to skipping this, and the change @Geoff (comment #16 above) mentions may be involved.

If you're not using one of the ruby remote form doodads, you'll want to not only set jQuery to munge the xhr headers, but also ensure the form is sent to /widget/69.js and not the default /widget/69

You can see the <a href="http://gist.github.com/111459">code snippet I use</a> at http://gist.github.com/111459

It's basically the same as in the railscast, but with the '+ ".js"' amendment in the jQuery.fn.submitWithAjax part

I also adorn the form's submit buttons with a spinner (using a CSS class), but that's just for shine.

As always, thanks a ton Ryan. Your episodes are monumentally helpful.

Avatar

Hi Ryan. I am very new to Ruby on Rails. Advance search is what I was looking to implement. I did try it out but facing some problems. when i render the partial I get an error sayin template missing. I create the partial but what do i put in the show method??

can you pls help

Avatar

Thanks for your railscast, Ryan! Nice compilation. I use mostly NewRelic for staging and production environments, and MySQL Query Reviewer for development mode:

http://flouri.sh/2008/4/10/mysql-query-reviewer-now-with-ajax-and-profiling

I find this last one really helpful and unobstrusive. You just put it in your app, no config files, and it will show a tiny floating div you can unfold to get more details of the queries, with helpful tips to get a better performance on them. Only works with MySQL, though.

Avatar

This guy documented all the steps without missing anything, use it it works:

http://snippets.aktagon.com/snippets/167-How-to-install-and-use-the-restful-authentication-Rails-plugin

Avatar

new_relic requires that you give them your email address and then they give you a config file. Otherwise you can't use it.

 Tune-up on Ubuntu doesn't work well because it creates files that require root access. I've been unable to find the correct chmod to resolve this problem as it seems to create some files each time at start-up.

Avatar

Thank you Ryan for your great efforts ;-)

Avatar

Hey Ryan, nice cast!

Got a off-topic question. What do you use to syntax-highlight your code snippets in the show notes?

I was looking around and couldn't find a good one.

Thanks!

Avatar

thanks for this, i was actually working on a app requiring this functionality not long ago but the whole authorisation thing with Restful_Authentication is so old; glad this gem freshens it up.

majorly glad all the core code doesn't go into my app, makes it a lot more cleaner.

Appreciate it

Avatar

And how can I profile actions which are called with Ajax?

Avatar

Ryan, what color scheme do you use in textmate? I like the colors you have when editing are they preset ones or did you customize?

Avatar

What is the best choice in production mode new_relic or 5runs?

Avatar

Two ways to do :

1.find(:all).map{|t| t.name}
2.find(:all).collect(&:name)

Avatar

The relic plugin isn't available at the momement
script/plugin install http://newrelic.rubyforge.org/svn/newrelic_rpm
.
.
.
+ ./lib/new_relic/config/ruby.rb
Plugin not found: ["http://newrelic.rubyforge.org/svn/newrelic_rpm"]

Avatar

You may want to note that rack bug only works with Rails 2.3 or later. I tried on 2.1 and 2.2 and doesn't work because there is no ActionController::Dispatcher

Avatar

Hey Ryan,

Question for you. On the create action of the sessions controller, the password field you have on there, how are you going about that?

I am trying to use <% form_for ...
but can't think of an object to reference it to, since we have no User model in this scenario. Can you paste your create.erb and destroy.erb file code? That part just doesn't make sense to me...

Avatar

Very cool. Thanks a bunch Ryan!

Avatar

Good news! Rails resources increasing! We got another site that posts podcast and video tutorials online! Just to let you all know this.. Please visit http://www.buildingwebapps.com/podcasts
We should really support these initiatives. Thanks Ryan and thanks Michael Slater/Christopher Haupt from LearningRails. You guys are doing a great job. Keep it up!

Avatar

It seems that every time I have tried to integrate Five Runs into my application, I always get buggy results. This time I can view the drop down information, but there is now way for me to delve in deeper into the models and queries. I think the latest may only be useful for Rails 2.3.2 and not older. I'm running 2.2.2.

Great screencast though, Ryan! I wish I could have made it to Railsconf so I could have met you in person.

Avatar

@Tim, I don't use any of these on a day-to-day basis, but I will boot one up occasionally when I need to figure out what Rails is doing.

Most often this is NewRelic's because it is most convenient if you are already using it for production too. But I am very intrigued by the other two, especially Rack::Bug which offers a boat-load of useful information and is extendable.

Avatar

Ryan, I would love to hear which one of these tools you like the best, and which one you use (if any).

Avatar

Comfirmed. You can use it as a gem in development too.

Avatar

Yeahhh, monday! I so waited this moment. ;-) An another great and useful screencast, thank you! Ryan for the win! :-)

Avatar

RPM is available as a gem as well, at least for production mode.

Avatar

Thanks for the excellent cast.
The various search methods in the search model can be now replaced by named_scope definitions. Is it right?

Nadav

Avatar

Always look forward to your screen cast every Monday morning! Keep it up!

Avatar

I got stuck on this for ages.

There seems to be a bug where the validations ignore :if or :unless parameters.

Here is the reported bug and a patch.

https://thoughtbot.lighthouseapp.com/projects/8794/tickets/131-validates_attachment_presence-should_validate_attachment_presence-should-take-if-and-unless-options#ticket-131-1

Avatar

Hi Ryan, thanks again for a great screencast. What do you prefer, webrat och cucumber for integration tests?

Avatar

@Toggo: Have a look at the gist. http://gist.github.com/108808

Avatar

This looks really good.
I like to test first and add functionality as I go, just ended
up deleting and rewriting a lot of RA.
My only question is does it offer the same level of security as RA,
hashing strength etc?

Apologies for going off topic but how do you get the syntax highlighting on the page?

Avatar

Hello Ryan,

The plugin is really nice.But when I tried to show an image inside a table it shows both the image and the array object.Can you please help me in removing the array object and show only the image.

Here is my code

items= @products_site.select{|site| site.category_id == category}.map do |site|

              [pdf.image("#{RAILS_ROOT}/public/images/message.jpg"),
                site.product.barcode,
                site.product.name,
                number_to_currency(site.price)]
           

            end
            pdf.table items,:border_style=>:grid, :row_colors => ["FFFFFF","EFEFEF"],
              :headers => ["IMAGE","ISBN", "TITLE", "PRICE"],
              :align => { 0 => :center, 1 => :center, 2 => :center, 3 => :center,4=>:center,5=>:center },:border_width => 0.04,
              :width=>500
        end

Avatar

I've followed this tutorial, but I have added another column to the comments model 'name', I'm not sure how to access this though in my view, as: article.comment.name, and variants of that give me the old undefined local variable or method error. Can anybody help?

Avatar

isn`t it hard to add
format.html { redirect_to(posts_url) }
to your comment_controller?

i`m serfing without javascript

Avatar

Yeah gotta thank you for this and nifty generators :)

Avatar

Authlogic is awesome. Now if we could get a railscast that integrates authlogic with rails-authorization-plugin (http://github.com/DocSavage/rails-authorization-plugin/tree/master)... That would be fantastic!

Avatar

I think that the use of "*files" in the helper method, looks like some kind of dereferenced pointer , but is a kind of understandig. God work - thx!

JOEY

Avatar

@Tim thanks I figured that one out...

Any thoughts on why the code doesn't pass the purchase_options to paypal?

Avatar

@Chris: Sorry, for the delay in replying, only just remembered I posted this (as I moved on to working on a different problem!). I'll have a look at the Party super and subtypes; didn't think of that. :-)

Avatar

Authlogic is working for me pretty good. However I am not able to get the documentation how to create a valid users.yml for functional testing. Any hints for me?

Avatar

Is it possible to use activeresource with MacRuby? I'm having troubles.

Avatar

This plugin helped me a lot past few weeks when I by chance stumbled upon it as well. As I haven't been using RA due to the lack of customization this is really neat.

Thanks for the great Screencast.

Avatar

My transactions suddenly seem to be going through to PayPal's development sandbox without any Billing information.

Do other gateways allow actual transactions without billing info (now possibly PayPal again)?

Avatar

Clearly explains the usage of custom controller action along with :collection & :member routing resources.

Thank you Ryan

Avatar

General tip: For the plugin installation command to work in the command line, be sure you've got git installed. Otherwise, the command fails silently.

Avatar

I stumbled across authlogic just a few days ago, then all of a sudden this pops up. Great screencast, can't wait to try it out for a project I'm starting!

Avatar

i get undefined method `title'. what is this 'title' anyway?