RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

This is what I'm experimenting with, not sure if there's a better way:

ruby
entry << "<media:thumbnail url=\"#{post.thumbnail.tiny}\" width='200' height='200'  />".html_safe
Avatar

twitter_id, facebook_id, linkedin_id, plus_id work for me.

Performance-wise I would say it's just extraneous joins or database calls to get the info.

If they aren't authenticated with that service the value is null.

Normalization here is not necessary due to the has_many relationship being constrained.

Avatar

Thank you Ryan, very interesting episode!
I'm trying to get the mailer to work on heroku. I did
heroku addons:add sendgrid:starter
but whenever I try to send an email from heroku, I get this error:

ruby
2012-07-18T23:14:05+00:00 heroku[router]: GET guestlist12.herokuapp.com/assets/application-ea8b32131f736b7d8bc98f7cb199c9cf.css dyno=web.1 queue=0 wait=0ms service=11ms status=304 bytes=0
2012-07-18T23:14:10+00:00 app[web.1]: 
2012-07-18T23:14:10+00:00 app[web.1]: 
2012-07-18T23:14:10+00:00 app[web.1]: Started POST "/password_resets" for 68.5.179.249 at 2012-07-18 23:14:10 +0000
2012-07-18T23:14:10+00:00 app[web.1]: Processing by PasswordResetsController#create as HTML
2012-07-18T23:14:10+00:00 app[web.1]:   Parameters: {"utf8"=>"", "authenticity_token"=>"H1VHMVJocUWdwzwVV0AbLB1Pfqgug+jT846sE794ISA=", "email"=>"cedric.waldburger@mediasign.ch", "commit"=>"Reset Password"}
2012-07-18T23:14:10+00:00 app[web.1]:   Rendered user_mailer/password_reset.text.erb (0.8ms)
2012-07-18T23:14:13+00:00 app[web.1]: Sent mail to cedric.waldburger@mediasign.ch (3117ms)
2012-07-18T23:14:13+00:00 app[web.1]: Completed 500 Internal Server Error in 3410ms
2012-07-18T23:14:13+00:00 app[web.1]: 
2012-07-18T23:14:13+00:00 app[web.1]:   app/models/user.rb:37:in `send_password_reset'
2012-07-18T23:14:13+00:00 app[web.1]: 
2012-07-18T23:14:13+00:00 app[web.1]:   app/controllers/password_resets_controller.rb:7:in `create'
2012-07-18T23:14:13+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):

Anyone else had this problem? Any ideas how to fix this?

Thanks in advance!

Avatar

hi,

I was following both omniauth episodes in order to get my app running with twitter authorization.
Unfortunately I am stuck when i call /auth/twitter .
I get redirect to my page to the create action in the AuthenticationsController
the weird thing ist that authentication.user is nil when in try to call sign_in_and_redirect

My validations model contains the belongs_to :user relation, but apparently it can not find the associated user.

Any help would be appreciated.
Thanks in advance.
Philip

def create
auth = request.env["omniauth.auth"]
authentication = Authentication.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
if authentication
flash[:notice] = "Signed in successfully."
puts authentication
puts authentication.user
sign_in_and_redirect(:user, authentication.user)
else
current_user.authentications.find_or_create_by_provider_and_uid(auth['provider'], auth['uid'])
flash[:notice] = "auth successfull"
redirect_to authentications_url
end
end

Avatar

With the facebook.js.coffee.erb the auth variable, in user model, is nil! I don't understand why! Someone can I help?

Avatar

I solved it downgrading to 2.1.0. I was using version 2.1.1.

Avatar

Hi everyone.

I did this exaple and works great.

I just have one question.

In the next code, ¿how I can change the label for the button?

ruby
<%= link_to t('.edit', :default => t("helpers.links.edit")),
                            liquidacion, :class => 'btn btn-mini' %>

Regards.

Avatar

So how would i go about redirecting a new user to a profile model so that they could fill in extra details about themselves?

Avatar

Is repeat a ZSH command? Is that available for bash? I can't figure out where you got it.

Can someone point me in the right direction?

Avatar

def sweep not working for me.

this yes:

ruby
 def sweep(banner)
    ActionController::Base.new.expire_fragment("fragment_tabs-banners-parnaiba")
 end

Just had to add: ActionController::Base.new.expire_fragment

Avatar

Remember to set the Content-Disposition header for such downloads.

Avatar

Cheers Pranay.

In case anyone else is using Kaminari - you might need to change '.next_page' to '.next' :)

Avatar

seconding juliamae's comment. this looks old if you're using rails 3.

"Rails 3 Way" has a chapter on authlogic.

Avatar

seconding juliamae's comment. this looks old if you're using rails 3.

The "Rails 3 Way" book has a chapter on authlogic.

Avatar

^^ If you just use 127.0.0.1:3000 for the callback, it works.

Avatar

Back button ... I'd like to know as well!

Avatar

in other words, please tell how to make it registrable + omniauthable

Avatar

normal registration form is also not showing the password field ..
how can I make sure its shown for users who want to register through site and not show the pass for user from oauth ..

Regards

Avatar

I'd love to send the email not only to the user but to myself as well. How would you do that?

Avatar

Hi Ryan, great episode indeed, well worth $9 itself.

I'm pretty curious about how to implement authentication via multiple services too. Any episode taking that path soon?

Avatar

Ryan - Thanks for this awesome RailsCast. I was trying to figure out RSpec and this made so much sense. Please create new RailsCasts about testing as your process changes and the tools improve.

Avatar

How would this work with other query parameters such as searches or paging? It seems that a simple search parameter added to the model is not recognized after the find_with_reputation call.

Avatar

I've also used cancan to limit the user from voting on their own Answer/Question/Post.

Cancan and Reputation
      can [:new, :create], Answer
      can :manage, Answer, :user_id => user.id
      can :vote, Answer
      cannot :vote, Answer, :user_id => user.id
Avatar

I've taken the concept of if a user has voted for something and taken it a step further. The user can see if they have up voted something or down voted something.

ruby
        def up_voted_for?(item)
                  eval = evaluations.where(target_type: item.class, target_id: item.id).first
                  eval.present? && eval.value > 0 ? true : false
        end
ruby
        def down_voted_for?(item)
                  eval = evaluations.where(target_type: item.class, target_id: item.id).first
                  eval.present? && eval.value < 0 ? true : false
        end

This came in handy when I was checking to see if the user has up voted or not so I could change the image.

up voted
      <% if can? :vote, answers %>
        <% if current_user.up_voted_for?(answers) %>
          <%= image_tag("color_up_arrow.png") %>
        <% else %> 
          <%= link_to image_tag("gray_up_arrow.png"), vote_answer_path(answers, type: "up"), method: "post" %>
        <% end %>
      <% end %>
Avatar

Had the same error...I ended up removing the ENV and [] from the CONSUMER_KEY and CONSUMER_SECRET in the devise.rb initializer file. I also used http://127.0.0.1:3000/auth/twitter/callback as my callback URL in the Twitter App settings and it seemed to fix the error for me. In case it matters, in the Website field I used my production url...http://myappname.com. Hope this helps.

Avatar

Did you ever find the answer for this Ben?

Avatar

Interesting talk at NDC 2012 on not so well known tid bits of Postgres

Avatar

So I discovered an odd problem with using Capistrano::CLI.password_prompt "PostgreSQL Password: "

I spent most of the day trying to figure out why I was getting this error
FATAL: password authentication failed for user "DBuser"
at the bundle exec rake RAILS_ENV=production db:migrate
stage of my cap deploy:cold.

Turns out that when I use special characters when prompted for the db user password during
cap deploy:setup, the cold deploy fails. But if I use a password without any special characters then the cold deploy works.

I don't know why this would be the case, so if anyone has any ideas as to why special characters can't be used, I'd love to be enlightened.

Avatar

you might be interested in this book? recently released by Pragmatic Programmers - http://pragprog.com/book/jkdepj/deploying-with-jruby "Deploying with JRuby: Deliver Scalable Web Apps using the JVM"

Avatar

I agree with your point of solving this in a model instead of a sweeper in the controller. It took me a couple of hours to solve this problem the IMO proper way.

Add the following to your model in a Rails 3.2 app (here the Class is Company):

ruby
after_create   :expire_cache
after_update   :expire_cache
before_destroy :expire_cache

def expire_cache
  ActionController::Base.expire_page(Rails.application.routes.url_helpers.company_path(self))
  ActionController::Base.expire_page(Rails.application.routes.url_helpers.companies_path)
end
Avatar

Hi,

I did all like in the guide, but on failed registration I got the following:

Routing Error

No route matches {}
Try running rake routes for more information on available routes.

Details of my issue can be found at http://stackoverflow.com/questions/11506734/routing-error-no-route-matches-when-omniauth-failed-on-registration

Does anybody have any ideas what can be the reason for this?

Avatar

Are there any solutions for integration testing to verify that secure cookies work as I expect?

Avatar

hi,

i can not use symbol '€', anyone can help me ?

Avatar

Ryan, thanks for another excellent railscast!

Hi everyone.. I have to say, setting it up initially wasn't very easy. Turns out rubber is not very happy with "complex" database.yml (with conditional environment if's etc..) or with hyphens in the app name which, at least when using mysql templates, confuse rubber.

After having fixed a few annoying issues - and separating the credentials, I now have a weird issue (and a question below):

The problem I hope someone can shed some light on:
cap rubber:create_staging runs without errors. However, it ends with the same output as rubber:bootstrap does. i.e. the last command is:
* executing "sudo -p 'sudo password: ' bash -l /tmp/create_master_db"
and never actually fires up an apache/passenger to run my app.. and thus the link is not accessible.
Also, a bit above, collectd throws an error:
** [out :: production.foo.com] Starting statistics collection and monitoring daemon: collectd
** [out :: production.foo.com] configfile: stat (/etc/collectd/conf.d/*.conf) failed: No such file or directory

Can collectd be the reason why my app doesn't actually start? I'm using rubber 2.0.5 by the way. Or may it be that it requires me to run another command to get things started (even on staging)?

And the other question:
I'm using the complete_passenger_mysql template - which hopefully includes everything - but was tempted to use complete_passenger_nginx_mysql - any benefit in doing this instead??

Avatar

Any Luck Here Tarik?

Getting the same error after authenticating Facebook via javascript based asynchronous call.

It works if I use the standard method where I am directed to login via Facebook website.

Thanks indeed for any help.

Avatar

"config.active_record.whitelist_attributes = true" only works in Rails 3.1 or greater.

Avatar

Thanks Ryan, I have been waiting for this one for some time now.

Avatar

Will, Thanks for sharing this. It's great to learn useful things in the comments section of Ryan's awesome site, too!

Avatar

I think it may be that it's more efficient to pass simple types to delayed methods as they get serialized and stored in the jobs table?

Avatar

As all ways great episode!

It would be nice if you could make an episode on the topic of creating a oauth service with devise and doorkeeper.