RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

An update! I got very very frustrated, and tried everything over again on a new machine. I went back to Rmagick and it worked this time. The key thing seemed to be with my setup. I'm not sure specifically what, but it had something to do with Ghostscript and/or MacPorts. Removing macports, reinstalling imagemagick, reinstalling rmagick, reinstalling ghostcript finally did it for me!

Thanks!

Avatar

Hi, I think Lee didn't use 'setup' method in his code, the same thing is happening to me and the output indicates the error occurred on actionpack-3.1.0/lib/action_controller/test_case.rb:12; Full trace is here https://gist.github.com/1453733. Any ideas? thanks!

Avatar

Nice screencast Ryan. I have a question though. It seems like this method allows selection of Country only once. Since the State dropdown gets reduced to only the matched states after a Country selection, if you select a new Country that has states, you've now lost the original list of states, so the States dropdown comes up blank. This means if a user makes a mistake selecting their Country, they would need to reload the page in order to undo that mistake. Please correct me if I'm just implementing this wrong.

Avatar

what the kaminari corresponding of page_entries_info?
I use it with will_paginate but I didn't find it in kaminari.

Avatar

These videos don't play well in Firefox on my souped up MBP 17". i have to use Safari or Chrome.

Avatar

Actually, it's my mistake, you are right, my credentials where wrong and I fixed it. so it'w working now. Thanks!

Avatar

Is anyone else having issues with playing videos on iPad?

Avatar

How secure is this authentication?

Is it safe enough to stick on the evil internet, on a Debian server using the Passenger mod for Apache?

What else do I need to consider?

Avatar

Hey, Great tutorial, but I'm running into an issue. Firstly RMagick didn't work for me. For some reason, every time without fail, it brought down my rails server when the method that does resizing was called. I found a bunch of people with the same issue, but none of the fixes, which generally included reinstalling both RMagick and Imagemagick, worked for me. The solution that got me a step further was switching to MiniMagick. Now images resize and are saved, but the next step is moving on to the actual cropping, this is now where I'm up against a new issue.

This was taken from my pdf_uploader.rb (despite the name PDF I'm currently only using jpegs just to avoid any potential difficulties there). This is my crop method, which looks pretty similar to the one in the tutorial. Someone on stack overflow also had an issue with the way your crop method worked and suggested I try something more like this:

ruby
  def crop
    if model.crop_x.present?
        img = MiniMagick::Image.open(model.pdf.path)
        x = model.crop_x.to_i
        y = model.crop_y.to_i
        w = model.crop_w.to_i
        h = model.crop_h.to_i
        img.crop(x, y, w, h)
        img
    end
  end

This doesn't work for me either even though I'm trying to explicitly edit the file. The reason has everything to do with "model.pdf.path" which I was told should do the trick... When I inspect "model.pdf.path" it prints out a tmp directory, rather than the path to where the file actually lives... This results in a big fat show stopping error, and no crop.

Errno::ENOENT in PiecesController#update

No such file or directory - /var/folders/dF/dFNM2+Y7FVScn4+OxVHKOU+++TI/-Tmp-/mini_magick20111208-45803-1027dqf.png
Rails.root: /Users/cory/Documents/Projects/TickiWiki

Application Trace | Framework Trace | Full Trace
app/uploaders/pdf_uploader.rb:78:in crop'
app/models/piece.rb:27:in
crop_pdf'
app/controllers/pieces_controller.rb:107:in block in update'
app/controllers/pieces_controller.rb:106:in
update'
Request

Parameters:

{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"4+QAJEMjn1YhG+7khKbTC/SxfSeKzONoSxTd+MoQNyM=",
"piece"=>{"crop_x"=>"10",
"crop_y"=>"371",
"crop_w"=>"476",
"crop_h"=>"307"},
"commit"=>"Crop",
"id"=>"240"}

This leads me to a few questions:
1. Why, what did I do to deserve this?
2. How can I get the correct value?
3. Will the correct value even make it work?
4. Is there a better way to do this?
5. Why can't I code as quickly and with as few mistakes as Ryan Bates in a RailsCast?

Anyway, this n00b would love any suggestions anyone has. Thanks!

Avatar

Could this be used for a single sign-on system? So that I have an authentication app running that passes out authentications to different apps?

Avatar

gem 'best_in_place_mongoid' :D

Avatar

best_in_place and mongoid are compatible?

Avatar

Sorry! It's:

ruby
update: ->
        $.ajax({
                type: 'post'
                data: $(this).sortable('serialize')
                headers: {'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')}
                url: $(this).data("update-url")
        })
Avatar

Im using Ruby 1.8.7 and Rails 3.1 and i was getting this error WARNING: Can't verify CSRF token authenticity when released the drag.

So i google it and I had to do a modification of Coffee Script:

ruby
update: ->
                        $.ajax({
                                type: 'post'
                                data: $('#banners').sortable('serialize')
                                dataType: 'script'
                                headers: 'X-CSRF-Token': '<%= form_authenticity_token.to_s %>'
                                complete: (request) -> 
                                        $('#banners').effect('highlight')
                                url: $(this).data("update-url")
                                })

I hope to help someone else who has this problem!

Avatar

Dido on that request.

I discovered this link. It might be of help:
Thin vs unicorn vs passenger (http://www.ruby-forum.com/topic/1822610)

Avatar

It worked fine on development but on production is does not work.

Avatar

Any support for using simpleforms to use jquery datepicker function?

currently have for start time
<%= f.input :start %>

How would I modify this to make it text field?

Avatar

It's now working for me, I wish I could delete this comment

Avatar

It's now working for me, I wish I could delete this comment. ;p

Avatar

I'd like to know too! Jon, did you figure that out already?

Avatar

If your using attr_accesible on your model make sure :remove_image is set there, and it should work

Avatar

what else needs to be added for something like this github feature

Avatar

Hmm...not getting anything. Is there a way to see output of what ActionMailer is doing?

I'm using Rails 3.1 and following http://guides.rubyonrails.org/action_mailer_basics.html

Avatar

Did you have any issues with the two gems conflicting or was it pretty straight forward?

Avatar

Having issues with minimagick. Instead of

ruby
img.crop!(x, y, w, h)

I had to do:

ruby
img.crop "#{model.crop_x}x#{model.crop_y}+#{model.crop_w}+#{model.crop_h}"
img

But the thumb version of the image is not displaying properly.

Avatar

Hi, I am new on Rails and I really like this screen cast to implement on my first app. But wonder if this screen cast is applicable on a real domain, cause most of comments here are pointing to localhost.

I wan't to use it on my testing domain which is http://ngtv2.info/ and if possible, to have i.e. kingpangilinan.ngtv2.info

Even though I include this code in my routes.rb

ruby
match '/' => 'projects#show', :constraints => { :subdomain => 'kingpangilinan' }

I still get a Server not found Firefox can't find the server at kingpangilinan.ngtv2.info when I browse for http://kingpangilinan.ngtv2.info/

I wonder how I will implement it using my ngtv2.info instead of lvh.me:3000 or localhost:3000

Avatar

Hi, I am new on Rails and I really like this screen cast to implement on my first app. But wonder if this screen cast is applicable on a real domain, cause most of comments here are pointing to localhost.

I wan't to use it on my testing domain which is http://ngtv2.info/ and if possible, to have i.e. kingpangilinan.ngtv2.info

Even though I include this code in my routes.rb

ruby
match '/' => 'projects#show', :constraints => { :subdomain => 'kingpangilinan' }

I still get a Server not found Firefox can't find the server at kingpangilinan.ngtv2.info when I browse for http://kingpangilinan.ngtv2.info/

I wonder how I will implement it using my ngtv2.info instead of lvh.me:3000 or localhost:3000

Avatar

I think this pollutes the namespace in the view too much. Is avatar a helper method? instance var? presenter method of @user? It's not clear any more.

Avatar

And you're sure your credentials (key and secret) are correct and set in the environment?

Avatar

I've implemented this months ago without any pain. But today when I moved my application to a newer debian-server, it told me "easy_install not found.

If you face the same trouble use:

sh
sudo apt-get install python-pygments
Avatar

First of all, thanks for a great in depth episode!

I would definitely love to see cancellation / card decline situations being handled in the next ep. Thanks Ryan.

Avatar

I keep getting:
Uncaught TypeError: Object # has no method 'autocomplete'

I've included jQuery UI in application.js:
//= require jquery-ui

... and my coffeescript:
jQuery ->
$('#location').autocomplete
source: ["foo", "food", "four"]

What am I missing!?

Avatar

Hi, does anyone know how to use the snippets function?

Avatar

Another small update from version 1.0 of omniauth you will need to change the key user_info TO info in the user model ie.

ruby
self.email = omniauth['info']['email'] if email.blank?
Avatar

Hi,

I downloaded the source code, when I try to use google (and I need to use it), I get

http://localhost:3000/auth/failure?message=invalid_credentials

Any hint please?

Avatar

I personally prefer how you integrated omniauth with Devise in episode #236. Do we need to point the omniauth gem to an earlier version to keep that working?

Avatar

Thanks for sharing this. It was really timely and helpful, as is often the case.

One thing to point about about using the :git repo notation in your Gemfile: it's usually not a great idea to do this if you don't control the repo. Since the rubygems service controls versioning more tightly, you can bet that when new code is released, the version will bump. However, the same cannot be said for master branches on github, which could lead to nasty surprises when you bundle install.

Avatar

has anyone used this with paperclip or carrierwave for swapping out images on-the-fly?

Avatar

Yeah, if you're using Devise, then you're already using Warden without knowing it.

Avatar

The warden method is private, so it's not accessible as an action. It only needs to be made a helper method if you intend on accessing it from your views.

Avatar

Shouldn't "def warden" be a helper method? At least, we should hide it as action.

Avatar

Consider the previous screencast by Ryan where he does a TDD based overview of adding in the remember me and forgot password into the first 'auth from scratch' application. I would imagine a similar approach here would work fine.

As for sending out emails etc, these can be done in the sessions#create action but do not sign the user in. Instead, you'd generate a confirmation token (which is emailed) and setup another general controller expecting someone to visit it with that token as a parameter - inside the action, you can handle the auth process and even automate the user login and enable whatever attributes on the user in question to indicate they've confirmed their email address.

Avatar

I was getting 401: Unauthorized errors for twitter so decided to give Facebook a try. This caused

json
{ "error": { "message": "Missing client_id parameter.", "type": "OAuthException" } }

The solution was to remove the ENV[ ] from the initialiser for both twitter and facebook and it seems to be working fine.

Avatar

That's the whole point, and that's done by the omniauth gem itself. Once you authenticate against twitter, the 'callback' URL is visited which is handled within the Rails app - note the custom route to handle it in routes.rb

Avatar

I recommend on_the_spot - Great Gem and Nathan is a badass.

Avatar

Excellent screencast Ryan! Always incredibly helpful!

By the way, I created a basic formatting gem based on your gem publishing screencast called validates_formatting_of. This eliminates the need for pasting in special regex (and allows custom regex if you want). Thought I would throw that out there for you to take a look at.

Avatar

Great screencast Ryan, shows how great tool omniauth is. I just have one question, kinda in the lines of what Josh said earlier - how do you integrate this with Devise? I noticed there are no features like forgot password or confirmation emails using identity so how would you go about implementing those?

Avatar

If working with an app to provide email/password AND external authentication, would this be the way to go over OmniAuth/Devise in combination?