RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

The selenium tests on the demo app of this episode doesn't work [rails 2.3.8, ruby 1.8.7].

Trace: http://pastebin.com/RSWDeZp6
Screenshot: http://is.gd/iPbXd

Thanks

Avatar

@Phillip (I know, more than a year later):
I think your issue is the same as mine. For example, in Ryan's example, if Photos were nested in Articles, find_commentable would not work correctly. Assuming a RESTful API, then you need to retrieve $1 from the request.request_uri (note my example uses 'imageable' as opposed to 'commentable'):

    def find_imageable
      pathArray = request.request_uri.split('/')
      if pathArray.count > 2
        if pathArray.count % 2 == 0
          imageableString = pathArray[pathArray.count-3].singularize
        else
          imageableString = pathArray[pathArray.count-4].singularize
        end
        @which_id = imageableString+"_id"
        if pathArray.count % 2 == 0
          return imageableString.classify.constantize.find(pathArray[pathArray.count-2])
        else
          return imageableString.classify.constantize.find(pathArray[pathArray.count-3])
        end
      else
        params.each do |name, value|
          if name =~ /(.+)_id$/
            @which_id = name
            return $1.classify.constantize.find(value)
          end
        end
      end
      nil
    end

Avatar

Hi, I am using Mongoid as database, does anyone know if it is safe to use regular expression matching for a string field in that self.search method for individual users?

like current_user.projects.where(:name => /#{params[:search]}/i)

Thank you

Avatar

Hi Ryan,

This again is a remarkable screencast! We really can't praise your importance for the Rails community enough. This screencast has been an eye-opener for me, to say the least.

One question though: I can't seem to figure out how to set attr_accessible dynamically for fields from a related-model?

I have a form for a model x that uses 'accepts_nested_attributes_for' model y. Model x has_many model ys.

If I find the answer myself, I'll post it here!

Kind regards, Kristof

 

Avatar

What's the easiest way to uninstall simple form from rails3 project?

Avatar

Hi Ryan,

nice again! One question: for me the title helper method does not work because it's not known (undefined method `title' for #<#<Class:0x000001036106d0>:0x000001037527c8>). In other (not Devise) views it works like a charm. Could that be because Devise is Rack-based? Did I something wrong?

Thanks i.a.,
Mark

Avatar

Nice! Gravatar support was one of my first things I wrote in my very first project in Rails and described it on my blog.

Avatar

I've been doing this forever so I kind of feel like it's a waste, but hopefully people that don't use gravatar will now be convinced to use or or introduced to it.

Avatar

Nice short and sweet episode!

I was hoping you were going to "roll your own" gravatar support instead of using an unnecessary gem/plugin. I appreciate the effort behind stuff like gravtastic and all, but it seems like overkill in this case.

Avatar

Nice episode. Good timing as I was just thinking about implementing gravatar images the other day!

Avatar

Isn't named_scope a better way to implement the same?

Avatar

Thanks Ryan for the simple explanation. I am currently using a Gravatar gem on project but it got kinda messy. I believe this approach will work well for my app.

Avatar

Authorizing with github... is that part of OmniAuth?

On the subject of OmniAuth, is it only authentication or is it Authorization? Before OmniAuth was released I created http://theSociable.me which uses oauth and oauth2 and authorizes 4 different social media's for posting (FB, twitter, buzz, and linkedin)

I didn't know that working with gravatar outside of a plugin was so easy... One comment is that I don't believe you put any size constraints on the users' avatar url ... that might cause some issues.

Not sure if I will use this since I have already implemented the user profile image cropping on another site and really like the flexiblity of that solution.

Mark

Avatar

This is also a great way (gem), how I handle this.

https://github.com/chrislloyd/gravtastic

Avatar

Very nice. Very clear. I can't wait to try it.

Avatar

Hello,

1. I didn't know github had this nice cross-authentication... finally the spam is gone. THANK YOU!

2. on your promise on "more in depth" stuff: I loved #240 http://railscasts.com/episodes/240-search-sort-paginate-with-ajax but it misses UJS-JQuery-Anchor-Tag addons for transparent back/forward browsing

I did try to adapt from #175: http://railscasts.com/episodes/175-ajax-history-and-bookmarks on Rails 3 but it didn't work for me... would be great if you could add an enhancement session on #240 on this topic maybe using the more recent BBQ http://benalman.com/projects/jquery-bbq-plugin/ or something alike. I am not deep into JS/JQuery and could not make it work for hours :/

Thanks in advance and keep up the awesome work!

Avatar

Is there any downside to using Gravatar? I know that on my wife's blog we disabled the gravatars because the comment threads were taking forever to load because of all the gravatar calls. This sort of optimization is outside of this episode but it would be cool to discuss how to efficiently pull resources from outside services.

Avatar

Almost overkill to point out that the shorter Railscasts have often lots of value, and hey why make it more complicated than it is ;).
Thanx for this episode as much as for all the others.

Avatar

is there any way to rename the fieldname in the form for Simple Form?

im getting this error because I dont have this attribute on db.

unknown attribute: ref_states_id

the fieldname in the form supposed to be state !

Avatar

@Arcath - Yeah I threw together a similar helper method for a side project I've been working on.

https://gist.github.com/738893

Avatar

BTW, shameless plug, for anyone willing to have the video embedded in this page (as HTML5 video tag), install this in safari: https://github.com/stuffmc/Embedded (download the .safariextz) - I hope to find some time to work on this toy again in the future :)

Avatar

I would actually like to see more micro episodes like this one. Keep them coming!

Avatar

I confirm: It's okay to have an easy episode once in a while :) Thanks for the great work Ryan!

Avatar

It's okay Ryan. Easy episodes once in a while is just fine.

I'm already using Gravatars but I learned a couple things from this cast.

Avatar

I wrote a helper method to do this that takes option as a hash

https://gist.github.com/481321

this lets you do the same but isn't specific to a user model

Avatar

Hey Ryan thanks for putting this together for us. Its AWESOME and has really accelerated the learning curve for my journeys on rails.

I am having a problem with this though, for some reason I am throwing this error:

"undefined method `id' for user:Symbol"

on the

"sign_in_and_redirect(:user, authentication.user)" step of your instructions.

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

Have you seen this type of an error before?

Avatar

@ryan bates

@robert

Thanks for correction re persistence.

Avatar

Oops... Sorry... Chirstopher Small isn't a spammer.... clicked one too much... Apparently searchlogic still isn't Rails3 ready :( Maybe you should put a big warning on top of this post (and as well for all others plugins/gems not compatible with rails3)

Avatar

Signing through GitHub?! Cool! ;-) Hope it blocks spammers.

I think it makes no real sense to says "yes" for application_controller and application_helper since they are empty from "rails new" and have the same "declaration" as in rails 2.3 so it's easier to say "no" there.

Avatar

@Alfred set the callback to http://127.0.0.1/auth/twitter/callback if you want to test it locally.
@ryan thanks for all the awesome screencasts, very much appreciated!

Avatar

This was just awesome.

+1 for a testing episode with omniauth.

Avatar

Love the new Github sign in and thanks for your hard work.

Avatar

Comment while signed in from Github. Thanks Ryan!

Avatar

@Marquisdebad It really depends on what you want from a queue system. I personally use beanstalkd to process incoming email on an app. It's not supposed to be as powerful as the other options you suggest; it's a simple and very fast queue system.
A couple of corrections for you:
* it does have persistence; launch the daemon with -b
* it may not have the size of userbase as DJ, but it does have some very high traffic users. I believe http://ravelry.com does for a start (and obviously Causes on Facebook, for which it was created).

I love it because it's incredibly simple :)

Avatar

@Luke, you can certainly connect to any server running Beanstalkd, it's not necessary to do it all over the same server. However authentication is up to you.

@Sohan, I place the jobs in the config directory because it is very similar to deploy.rb for Capistrano. It requires an external dependency (stalk command) to run it and in a sense it is configuration for Stalker.

See my response to Nico above for how this compares to Delayed Job.

@Marquisdebad, Beanstalkd does have persistance with the "-b" command, however I prefer to use it in situations where persistence isn't necessary. That is where you can requeue anything based on the database.

Also authentication isn't a problem if Beanstalkd is running on the same server as your app. Just block external traffic to that port.

Beanstalkd is lightweight and fast. It is event driven which means it responds instantly to the jobs and doesn't do constant polling. I find that to be its biggest advantage.

@Yorick, I just switched to GitHub authentication for commenting here which should take care of the spam problem.

Avatar

Sweet Jeebus in a minivan stay away from beanstalkd!

* no authentication
* no persistence
* very little queue management
* tiny user/support base
* minimal interop

Ruby users have at least 4 better options for queue management:

* DelayedJob
* Resque
* amqp/nanite
* xmpp4r

Please please you owe it your children, and their children, to evaluate those other options first.

Avatar

congratulation Ryan for the great screanshot!!!

I'm using prawnto now I feel that I'm in right way!!!

Avatar

Hi Ryan, I have two questions:
1. Why do you like putting jobs inside the config? It looks a bit odd to me.
2. How would you compare it with delayed_job?

Thanks!

Avatar

This is really a terrific deal for a critical article, I seriously discovered your blog by mistake when researching on Msn for some thing diffrent closely connected, in any case prior to I ramble on too a lot I would just like to say simply how much I cherished your article, I

Avatar

Has anyone successfully adapted this approach to Authlogic? Specifically the parts that allow the user to complete user fields after authenticating? I've checked out madhums excellent demo at https://github.com/madhums/omniauth-authlogic-demo but it doesn't cover that use case.

Avatar

There's one important thing to know if you want to share sessions between subdomains on localhost. Using :domain => ".lvh.me" not always works (in my case it didn't), so you have to configure your environment as described in http://blog.plataformatec.com.br/2009/12/subdomains-and-sessions-to-the-rescue/

Avatar

Great screen cast, Ryan!
Came just in time when I needed it! :)

Avatar

Anyone have problem with installing 'brew install beanstalk' on Mac 10.5.8?

Avatar

It seems like this will only connect to beanstalkd if it is running on the same host. How would you connect to a remote beanstalk queue?

Avatar

Stalker adds logging at a layer above beanstalkd, so it can help mitigate one of the problems Knodi describes.

Avatar

How do you install the AuthButtons?