RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Can you make a new one, applying to the rails 3, please?

Avatar

@users/1488: I would guess you have to use a separate channel per user. Then the trick is to get the application.js to listen on this channel, as it has to be generated per user. Not sure how to do that yet, but I'm sure someone more used to Javascript and Rails will be able to tell you how.

Avatar

big big thanks from Beijing China

Avatar

Thanks for another great screencast Ryan!

I am running into a routing error that I am not sure how to solve - feels like I am missing something obvious as I don't see anyone else reporting this.

When I go to 127.0.0.1:3000/auth/twitter I get a
routing error

No route matches "/auth/twitter"

I have the "gem omniauth" in my gemfile (and installed through bundler) and I have omniauth.rb where I have setup twitter connection as suggested.

The server starts up fine - the home page loads. I am on Ruby
1.9.2p180 and Rails 3.0.5 on a Win box.

How does this /auth/twitter route get interpreted? Does Omniauth do it behind the scenes somehow by extending the routes.rb?

Thanks for any thoughts or pointers.

Avatar

Hi all. this railscast is awesome. But i've question, how to push a message for specific client. For example in facebook, if somebody send me a message or tag my photo, that was notification only for me. Thanks

Avatar

This episode was very informative. A note about the "ratio" variable in JS. This shouldn't be necessary to embed into the JS since it can be done from the custom Cropper class that you created. I find this to be cleaner, safer, and lighter on the client side.

Avatar

Thanks for the nice RailsCast. Slightly changed your code to work with AR attribute type as well:

https://gist.github.com/919326

Avatar

worth pointing out that Diaspora has a bunch of jasmine specs if you want more examples!

https://github.com/diaspora/diaspora/tree/master/spec/javascripts

Avatar

Thank you so much Ryan for the wonderful work on Railscasts.

I'm trying to work my way through this video - after I add the omniauth.rb with

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :twitter, '-----', '-----'
end

I'm unable to start my app - it throws an error saying

/Users/---/---/config/initializers/omniauth.rb:1: undefined method `application' for Rails:Module (NoMethodError)
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:171:in `load_without_new_constant_marking'

Any ideas what might be causing this? I feel like I'm making a fundamental mistake. I'm using devise 1.0.10, ruby 1.8.7 and rail 2.3.11.

Tim

Avatar

Ryan,

I am working on SaaS based Application and I have company_id in all tables for multi-tenancy.

How can I use cancan for this application?

Avatar

This is awesome. It's all going into my app tonight! Thanks Ryan!

Avatar

Once again a great vidcast.

The one about the token fields blew my mind.

I would suggest to make another one about multiple uploads. Since it's damn hard ( for a noob like my at least ) to get it working.

Thanks again for your great work and effort.

Avatar

I liked to see Jasmine too, but why are you use jquery selector for each action? It is very slow and ugly. Much better to cache the selector in the variables like this https://gist.github.com/916179

PS. sorry for my english

Avatar

@ryan

I liked see Jasmine in practice. Spec.js is only another solution, and...

Thanks for all! ;)

Avatar

See http://blog.locomotivellc.com/post/4544746167/query-trace for an ActiveRecord subscriber that shows where a query is called from.

Avatar

Alejandro, my capybara/selenium test gets stuck on the token input field with this message: Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError). Are you getting the same problem?

Avatar

@Jan, cool, I'll check out Evergreen. Thanks for the suggestion.

@Aaron, make sure that you're loading the files properly in the jasmine.yml file. Sounds like either jQuery isn't loaded or it's conflicting with something.

@Celestino, Jasmine isn't specific to the run environment, so you can use it without a browser as well. It is the Ruby gem which uses a browser based run environment.

Here's an example of using Node.js to test a jQuery plugin.

http://digitalbush.com/2011/03/29/testing-jquery-plugins-with-node-js-and-jasmine/

Avatar

Aaron - would love to talk to you about this. Jasmine doesn't do anything to $ at all and works fine w/ jQuery. We should be able to help you out.

And there are ways to run Jasmine specs headless if that's what you want to do.

Ryan - Thanks for featuring Jasmine!

Avatar

@Ponyo Blue
   
  reflect_on_association(association)

returns nil, make sure that 'association' variable holds correct name of the association for your model.

Espero que entiendes. Mi espanol no es bastante buen.

Avatar

Exactly what I was looking for after adding jquery token input to my app!

Avatar

I will show you another testing framework to javascript.

Spec.js is a testing framework built on top of Mozilla Rhino and Env.js. The idea is that you can run JavaScript tests without opening browsers, even for DOM manipulation.

http://rubygems.org/gems/spec-js

Avatar

finally something i can use for testing my apps js. thank ryanb

Avatar

Thanks, Ryan! I've been really needing to add testing into my latest app that's damn near all jquery & rails 3. I appreciate you diving into this subject.

Avatar

I've been using jasmine on a project. It's quite nice, and works pretty well. Though ive had problems when the code im testing uses jQuery. For example, i've had to switch $.each() to use a for loop instead because it couldnt recognize the window.$ function.

Avatar

Definitely check out Evergreen (https://github.com/jnicklas/evergreen) too, it's jasmine without generated code and Coffescript support.

Avatar

this is very nice as ususal!! wish you have a sample Autocompletion like this but using prototype instead of jquery!

Avatar

is it me only or someone else facing problem with multi parameter attributes problem which will return nil when Article.find("4da14b1447640b14eb000002").published_on but with published_on: nil, published_on(1i): "2011", published_on(2i): "6", published_on(3i): "10"

Avatar

Great episode, and I've studied it while creating Sorcery https://github.com/NoamB/sorcery

so thanks.

Avatar

Useful tools! Just info I need. :)

Avatar

Here is a nice solution how to test an app with subdomains using rspec http://stackoverflow.com/questions/2556627/rails-rspec-set-subdomain

Avatar

Great screencast Ryan, thank you! For mongodb store check here:

http://stackoverflow.com/questions/5315470/rails-i18n-backend-with-mongodb-mongoid/5591463#5591463

I don't know how, Ryan, but it looks like you are reading my mind. I just need this for my current project!

-----
www.congrats-from.me

Avatar

Oh, and thanks so much for all your work Ryan. This just made my week. I've been spending time trying to figure out how to get node and ruby working together and you just obviated that.

Giving Rails, faye and Backbone.js a try now.

Avatar

Does faye allow you to push a message through them using messaging queue like RabbitMQ?

Avatar

Estoy trabajando con Rails3 y tambien tengo el error:

undefined method `klass' for nil:NilClass

He aplicado todos los cambios que ya mencionaron pero sigue el error. Por lo que veo, el problema no est

Avatar

I like the idea of an explicit interface between controller and view, but I'm not quite sold on this particular solution just yet. Especially since the cancan gem already fulfills most of this, and also handles authorization.

Looking at https://github.com/ryanb/cancan/issues/317 it seems this combined solution is already in the works :)

Avatar

Really great work! I just want to know what about using juggernaut for server push?

Avatar

Brilliant article! I especially like the work. Thanks dude!

Avatar

The one of drawbacks of using instance variables is that they are nil by default, so your code could silently work incorrectly. decent_exposure help to catch unsused variables. thanks!

Avatar

I am new to rails and pickle testing. I want to use polymorphic_path for post's comment's new page. Is there any way to write it?

I tried

when /^#{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/
  polymorphic_path(model($1, $2), :action => $3) (I am just guessing here)

It is giving "wrong number of arguments (3 for 2)" error.

Also for post's new page:

when /^#{capture_model}(?:'s)? (.+?) page$/
  polymorphic_path(model($1), :action => $2)
 
It is giving ""undefined method `model_name' for NilClass:Class" error.

I am assuming that the polymorphic_path is for creating paths. Please correct me, if I am wrong!

Avatar

Hey Ryan,

First off, thanks so much for Railscasts- I don't know where I'd be without these!

Quick question- what is your take on the security of calling the PayPal url builder that you put in the cart model from a controller and just calling that action from the view to create the url, as opposed to sending the url directly to PayPal via hidden fields in a form?

I am trying to do the former, and it is working fine, and to the best of my knowledge, can't be viewed through a browser the way a hard-coded url can. I am still going to try and use encrypted data, but wanted to get your opinion on this method...

Thanks so much for all your hard work!

-Dan Rich

Avatar

Just wanted to add one quick comment regarding Goliath. Goliath isn't a web framework, it's more of an API framework.

The general use case for Goliath is to serve data through JSON, XML or whatever format that can be consumed by front end web apps or other applications.

For example at PostRank, we use various Goliath servers to power our APIs which serve data displayed by the Rails applications.

Avatar

I was having the same problem as comments #19 and 20 with custom query methods returning hashes rather than objects. I didn't find what I was looking for in the online docs, but looking at activeresource-2.3.5/lib/active_resource/base.rb line 544 I found a :from option to find. Using the syntax from the provided examples, I can get back a collection of objects from a custom query. The custom query just needs to send back a naked array of valid JSON objects. For example:

 [{"name": "John", "position": 1}, {"name": "Jane", "position": 2}]

Person.find(:all, :from => "/companies/1/people.xml")

Avatar

I'd also like to know if this is much faster than Cucumber -- that would be a huge win to me

Avatar

sudo gem install aanand-deadweight
didn't work for me but this did
sudo gem install deadweight
https://github.com/aanand/deadweight/issues/8

Avatar

I'm so sorry but have to tell you this too: take my previous comment, then in the mentioned offers controller add

expose(:offers){current_user.offers}
expose(:offer)

and voila...you have a sort of..caching nesting how much I can see

Avatar

Found out that if you put expose(:current_user){current_user} in combination with devise, this one little line is almost enough to access all submodules through it like a global var with meaning. In later controllers (assuming you have to log in as user) just using 'current_user.offers' etc

Avatar

Imho, sending requests to the pub/sub server from view code looks strange and doesn't fit in the Rails MVC paradigm.

In spite of this, Ryan, thank you for your great contribution to the rails community.

Avatar

Thanks to :

[quote]
73. Anders Heie Nov 03, 2010 at 22:59
I'm a noob, so forgive me if what I write is not the correct procedure. After spending a couple of evenings on this, I managed to get this working for Rails 3 with the following changes (I'm trying to summarize all the experiences above).

1. Changed cropper.rb to this
http://pastie.org/995357
(From Chris Your)

2. Move cropper.rb to the folder config\initializers

3. Added missing '=' in crop.html.erb:
...
<%= form_for @user do |f| %>
...

4. Remember to add crop_x, crop_y, Crop_w and crop_h to the list of your accessible attributes IF you have such a list:
attr_accessible :avatar, :crop_x, :crop_y, :crop_w, :crop_h

5. Added this line to my gemfile:
gem 'paperclip'

6. bundle install

7. Being on windows, I added the path to ImageMagick in my development environment:
Paperclip.options[:command_path] = "C:\\Progra~1\\ImageMagick-6.6.5-Q16"

I used the SHORT path with ~1, because I read somewhere there was a problem with spaces here.

8. Added jquery.Jcrop.min.js, jquery-1.4.3.min.js in public\javascripts folder

9. added Jcrop.gif and jquery.Jcrop.css in public\stylesheets folder

10. Added <%= yield(:head) %> in the <head> section in the application.html.erb file (needed for sample above)

11. Restart your server

Pfeyy... Hope that helps someone, it took a while to sort all this out :)[/quote]

WORK NICE NOW

Avatar

@Walter, yeah it makes sense. I initially thought the broadcast was being executed on the client side so that a hacker could tamper the data.

Avatar

@Jonas : I thought that too before looking more closely and running the app. Basically since the message view is a standard rails 3 form it has html escaping and csrf tag (look application layout <%= csrf_meta_tag %>): you can't post javascript nor html through the form nor can you post in the form from another site.

That leaves a curl post, which is closed due to the security with FAYE_TOKEN (and the fact if your server has a good firewall you close the 9292 for outside world). So in essence even though not at first glance it is pretty secure ;)

Now getting it working with https might be another deal (meaning a clever one can read messages from other rooms even when you implement authentication but that's true for facebook, twitter also).