Ryan I have followed your railscast to the T. However, whenever I try to access the page I keep getting a route error. The error I get is this
No route matches {:controller=>"equipment", :action=>"destroy"}. this makes no sense to me sense i am not even touching the destroy method. Please help, I have been wrestling with this for two days. Thanks
Nice. I have implemented copying my config examples as a rails generator (which is implemented in thor), but you're right, for more general purposes, thor shines (even as a full deployment system, I might add).
Does anyone know if there is some kinda fork of the workling pluging that works with rails 3? I tried the plugin Ryan posted above, but it misses the method allow_concurrency= for ActiveRecord::Base...
Just one remark - you can easily get rid of the last piece of JavaScript code (which I found very ugly). Read on my http://apohllo.pl/blog/rails-3-and-ujs-with-jquery.
Hello.
How to change link_to_remote to work in Rails 3.0?
link_to 'Do magic', :remote => true, ??
How to call rjs file, to perform some onclick action?
Hey, great tutorial on subdomains, is there a simple way to avoid carrying the subdomain around in all other matched or resourceful routes apart from root_url(), my navigation is full of links like:
http://personal.lvh.me:3000/terms/index
where I really want
http://lvh.me:3000/terms/index OR
http://www.lvh.me:3000/terms/index
Actually the default value for the title doesn't work for me (ruby 1.8.7 rails 3.0.3) because yield(:title) is not nil but blank, easy to solve
<%= yield(:title).blank? ? 'default' : yield(:title) %>
I am also getting the 401 error code, and I don't quite understand why.
I did not specify a callback URL, but that seems to set the negotiation to "client" rather than "browser" but adding a callback in the Twitter config for this app doesn't seem to fix it either.
Is there a debugging mode for oauth which will show the details of the SSL request being sent? Or a command-line tool to issue an oauth request? Or even a simple Ruby one? :)
When using OpenID Omniauth renders a page to enter your OpenID before it redirects you to the correct OpenID provider. The page it renders is fine enough, but how can I customize it or replace it so that I get the same design as the rest of my site?
I'm struggling with one problem regarding subdomains and nested resources. As nested resources become top level resources with a subdomain, the following seems to work
resources :blogs do
resources :articles
resources :comments
end
constraints(Subdomain) do
match '/' => 'blogs#show'
resources :articles
resources :comments
end
which allows
personal.lv.me:3000/articles to correctly go to articles#index where I do a blog.find_by_subdomain as a before_filter.
However, the problem comes in a named route when I try generate a url. If I do
<%= link_to "View all articles", blogs_articles_path(@blog) %>
I will get lv.me:3000/blogs/1/articles which is correct.
However, if, as a user, I am browsing personal.lv.me:3000/ rails will generate personal.lv.me:3000/blogs/1/articles, which is incorrect as it should be personal.lv.me:3000/articles
I can rectify this by doing <%= link_to "View all articles", articles_path %>, and the path will be correct. But now it will be broken again if I browse without a subdomain.
Is there anyway to get rails to automatically remove the nested resource from the path if a subdomain is detected?
For everyone struggling with the 401 Unauthorized error, here's the solution:
1. You have to register your web app at http://dev.twitter.com/apps/new
2. Under your new app settings, add localhost and 127.0.0.1 (redundant but ensures it works) as registered callback urls.
3. Replace CONSUMER_KEY and CONSUMER_SECRET in omniauth.rb with the values twitter gives you after finishing step 1.
4. Restart your web server and it should work. It did for me!
Be sure to log out of twitter or use a second browser after setting up everything or you'll automatically bypass the twitter.com log in and redirect pages.
I kept getting stuck with a 401 Unauthorized error, but a look through the comments of your previous tutorial revealed that I hadn't switched my Twitter application type to "Browser" in the Twitter control panel (Twitter sets it to "Client" by default).
It might also be helpful to note that the callback URL for development apps should be set to "http://localhost:3000/auth/twitter/callback" or similar in Twitter's control panel.
good job!
I have one question.
logout only set the session to nil, that is not real logout. anyone click login button will log-in again if the twitter is not logout and the page is not closed.
how to solve this problem? logout the page and meantime logout the twitter?
Could you make a episode to solve this issue?
I find myself coming back again to to your writings only because you have several very great insights and also you have been at this a really long time, that is really inspiring and tells me you understand your stuff. Thanks Ryan.Great Work
How would I assign the user_id to current_user.id for the nested model?
I have an Item class that has many datafiles (paperclip attachment model). I tried:
def create
@item = Item.create(params[:item])
@item.datafiles.build( :user_id => current_user.id)
end
The line @datafile.user_id=current_user.id in the datafiles controller works fine if I create a datafile in the datafile form but not when created in a nested item form.
I was trying to make this work with Metasearch and Simple_Form, but I couldn't get the Search Box to work with AJAX. It doesn't seem like it is even noticing that I am typing anything. Would love some pointers.
@jake - Variety has it's downfalls. By doing a casts on one area Ryan has been able to cover more advanced topics.
@9x4a - Unfortunately Facebook and Twitter aren't OpenID providers, so to capture this market (and you can't just ignore it) you need a solution that covers all major ID providers.
We started using Mongoid and then eventually switched to Mongomatic. It's leaner, quicker, and reading the code is so straightforward! Mongoid breaks in ways you can't even imagine, problem is you always get bit in the ass when your collection is big enough for it to be a pain to replace. As soon as we hit a few million documents, performance started to nose-dive. Now running Mongomatic with our own extension, went past the 100 mil documents mark a few weeks back, would never look back.
If you want to use Mongodb to its full potential, don't let Mongoid spoil the experience.
@Jake, authentication is a requirement in almost any application so I think it is worth covering thoroughly. OmniAuth is one of the greatest things to happen in the Rails authentication space in a long time, and I wanted to show off how simple it can make authentication.
There is some overlap here with the earlier episodes because I want this screencast to stand on its own. Thanks for the input though, and expect some more variety in the future.
@0x4a6f4672, the reason there are so many authentication solutions is because different apps have different requirements. OmniAuth is a current favorite of mine because it stays out of the way and allows you to fully customize how authentication works in your app.
@Nate, yes, that is correct. If one has an account with Twitter and then signs in through Facebook it will make a separate account. Supporting multiple types of authentication per account helps this problem, but does not solve it completely. This is one of the primary drawbacks of offering third party authentication like this.
@Hubert, thanks for the suggestion. Testing is something I hope to cover more of in the future.
@ippa, the session is stored in a cookie by default, but it is encrypted and not editable by the user. However it is possible for him to see the contents of it, so just be certain to not put sensitive information that you don't want the user to see there. In this case it is okay if he sees his user id.
@Ryan can you please elaborate on how OmniAuth can work with Google API? for example access youtube data for uploading? Is there even a link between the two??
However, with all those OmniAuth / social networking integration, I see on thing is missing from your screencasts: testing.
I am pretty sure that lots of people who want to integrate or base their authentication solutions on, say, Twitter, think "but how the hell I use that in Cucumber tests"?
Maybe it's worth creating a screencast about: how to integrate that sign, how to mock it or provite alternative sign in just for running tests -- creating "myapp-test" twitter account and using it to sign in is not only not fun but also slow and painful.
Amazing that you can pull off a reliable authentication solution is about 30 lines of code.
I'm creating a new application and after watching this I'm re-evaluating whether I need to have the user/password or whether I just want to go this route with simple authentication.
Thanks for doing this Ryan.
Q. You mentioned a few times that this method doesn't handle multiple authentications. Does that mean that each user can only use one authentication provider? I'm assuming so because the application obviously allows a choice of multiple authentication providers. What would happen if a user used Twitter and then tried to sign-in with Facebook? Would you get duplicate user accounts?
Leave it to @wycats to create useful tools for the rest of us.
I can't thank you enough for these screen casts, they are my go-to ruby on rails reference library.
Ryan I have followed your railscast to the T. However, whenever I try to access the page I keep getting a route error. The error I get is this
No route matches {:controller=>"equipment", :action=>"destroy"}. this makes no sense to me sense i am not even touching the destroy method. Please help, I have been wrestling with this for two days. Thanks
rake is a tool tested by time. Thank you Ryan for good introduction for new tool, but I will stick with rake.
I believe you could use require "./config/environment" in 1.9 :)
Nice. I have implemented copying my config examples as a rails generator (which is implemented in thor), but you're right, for more general purposes, thor shines (even as a full deployment system, I might add).
How to define rails environment in which Thor will run?
I do not see really as competitors, more as complementary services, rake for the local project and thor for more system-wide tasks.
An interesting article I learned a lot
Great episode again! How do you do that your config/environment.rb gets required within a second? I get 15 seconds always.
would be great to have another railscast using carrier wave instead of paperclip for cropping
Does anyone know if there is some kinda fork of the workling pluging that works with rails 3? I tried the plugin Ryan posted above, but it misses the method allow_concurrency= for ActiveRecord::Base...
Just one remark - you can easily get rid of the last piece of JavaScript code (which I found very ugly). Read on my http://apohllo.pl/blog/rails-3-and-ujs-with-jquery.
Hello.
How to change link_to_remote to work in Rails 3.0?
link_to 'Do magic', :remote => true, ??
How to call rjs file, to perform some onclick action?
Hey, great tutorial on subdomains, is there a simple way to avoid carrying the subdomain around in all other matched or resourceful routes apart from root_url(), my navigation is full of links like:
http://personal.lvh.me:3000/terms/index
where I really want
http://lvh.me:3000/terms/index OR
http://www.lvh.me:3000/terms/index
Thanks in advance!
thank you very much Ryan! Everything is always so clear!
In _error_messages can get the name of the resource which you couldn't save in this way:
... prohibited this <%= target.class.to_s %> from being saved
thanks again!
Thanks once again Ryan - very professional!
Actually the default value for the title doesn't work for me (ruby 1.8.7 rails 3.0.3) because yield(:title) is not nil but blank, easy to solve
<%= yield(:title).blank? ? 'default' : yield(:title) %>
but still odd...
Hi!
Thanks for cool screencast.
I think, I found a security problem with your code. Please, correct me, if I'm wrong.
I think, it is possible to call 'destroy' and 'destroy_multiple' by modifying URL and remove any comments without being administrator.
Am I right?
Is it possible to prevent such attacks without adding 'if admin?' checks in nearly each method?
Regards,
Boris Brodski
I am also getting the 401 error code, and I don't quite understand why.
I did not specify a callback URL, but that seems to set the negotiation to "client" rather than "browser" but adding a callback in the Twitter config for this app doesn't seem to fix it either.
Is there a debugging mode for oauth which will show the details of the SSL request being sent? Or a command-line tool to issue an oauth request? Or even a simple Ruby one? :)
Hi,
And tried to implement the code, everything worked well in development environment. when I executed using rails s -e production, I get the error below
omniauth_callbacks_controller.rb:1: uninitialized constant Devise::OmniauthCallbacksController (NameError)
Can anyone help?
Great and simple, thank you Ryan!
When using OpenID Omniauth renders a page to enter your OpenID before it redirects you to the correct OpenID provider. The page it renders is fine enough, but how can I customize it or replace it so that I get the same design as the rest of my site?
Very very cool.When your mans not asleep at the lights for half a second hes gonna do a 6.99. S
Hi Ryan,
I'm struggling with one problem regarding subdomains and nested resources. As nested resources become top level resources with a subdomain, the following seems to work
resources :blogs do
resources :articles
resources :comments
end
constraints(Subdomain) do
match '/' => 'blogs#show'
resources :articles
resources :comments
end
which allows
personal.lv.me:3000/articles to correctly go to articles#index where I do a blog.find_by_subdomain as a before_filter.
However, the problem comes in a named route when I try generate a url. If I do
<%= link_to "View all articles", blogs_articles_path(@blog) %>
I will get lv.me:3000/blogs/1/articles which is correct.
However, if, as a user, I am browsing personal.lv.me:3000/ rails will generate personal.lv.me:3000/blogs/1/articles, which is incorrect as it should be personal.lv.me:3000/articles
I can rectify this by doing <%= link_to "View all articles", articles_path %>, and the path will be correct. But now it will be broken again if I browse without a subdomain.
Is there anyway to get rails to automatically remove the nested resource from the path if a subdomain is detected?
I really enjoyed the article. It proved to be Very helpful to me and I
am sure to all the comment here!
For everyone struggling with the 401 Unauthorized error, here's the solution:
1. You have to register your web app at http://dev.twitter.com/apps/new
2. Under your new app settings, add localhost and 127.0.0.1 (redundant but ensures it works) as registered callback urls.
3. Replace CONSUMER_KEY and CONSUMER_SECRET in omniauth.rb with the values twitter gives you after finishing step 1.
4. Restart your web server and it should work. It did for me!
Be sure to log out of twitter or use a second browser after setting up everything or you'll automatically bypass the twitter.com log in and redirect pages.
Hi Ryan,
Great tutorial and introduction to Omniauth.
I kept getting stuck with a 401 Unauthorized error, but a look through the comments of your previous tutorial revealed that I hadn't switched my Twitter application type to "Browser" in the Twitter control panel (Twitter sets it to "Client" by default).
It might also be helpful to note that the callback URL for development apps should be set to "http://localhost:3000/auth/twitter/callback" or similar in Twitter's control panel.
Thanks,
Chris
Great video! Thank you!
Is it possible to render both login form and forgot password in my layout ?
Thanks and i will bookmark your sitee
Hi Rany,
good job!
I have one question.
logout only set the session to nil, that is not real logout. anyone click login button will log-in again if the twitter is not logout and the page is not closed.
how to solve this problem? logout the page and meantime logout the twitter?
Could you make a episode to solve this issue?
Thans
Another great 'cast
+1 for testing
I find myself coming back again to to your writings only because you have several very great insights and also you have been at this a really long time, that is really inspiring and tells me you understand your stuff. Thanks Ryan.Great Work
I would also be interested in more episodes like this one.
Thanks for the great series of videos... has helped me tremendously!
It would be intresting for me to know who has won this contest...?
What was the textmate key combo you used to make the 'if and else' completion?
How would I assign the user_id to current_user.id for the nested model?
I have an Item class that has many datafiles (paperclip attachment model). I tried:
def create
@item = Item.create(params[:item])
@item.datafiles.build( :user_id => current_user.id)
end
The line @datafile.user_id=current_user.id in the datafiles controller works fine if I create a datafile in the datafile form but not when created in a nested item form.
Cheers J.
I am facing this when I am going to run : spec spec/models/article_spec.rb --format specdoc
`require': no such file to load -- /home/barek/projects/blog/spec/spec_helper (LoadError)
Please help me
I was trying to make this work with Metasearch and Simple_Form, but I couldn't get the Search Box to work with AJAX. It doesn't seem like it is even noticing that I am typing anything. Would love some pointers.
Hi!
I'm agree with Hubert and I'm pleased to know you'll cover more testing (devise...?)
I would really like to see also how to build a RESTful API.
Thanks a lot for this screencast!
I tried a very simple example but I get the following error:
ArgumentError in Admin/usersController#index
wrong number of arguments (1 for 2)
## UsersController
def index
@search = User.search(params[:search])
@users = @search.paginate( :page => params[:page] )
end
## index.html.erb
<% form_for @search do |f| %>
<%= f.label :name_like, "Name" %>
<%= f.text_field :name_like %>
<%= f.submit "Submit" %>
<% end %>
I have no idea what this error is. Can anyone help?
Thanks,
Thanks for another great post Ryan.
@jake - Variety has it's downfalls. By doing a casts on one area Ryan has been able to cover more advanced topics.
@9x4a - Unfortunately Facebook and Twitter aren't OpenID providers, so to capture this market (and you can't just ignore it) you need a solution that covers all major ID providers.
We started using Mongoid and then eventually switched to Mongomatic. It's leaner, quicker, and reading the code is so straightforward! Mongoid breaks in ways you can't even imagine, problem is you always get bit in the ass when your collection is big enough for it to be a pain to replace. As soon as we hit a few million documents, performance started to nose-dive. Now running Mongomatic with our own extension, went past the 100 mil documents mark a few weeks back, would never look back.
If you want to use Mongodb to its full potential, don't let Mongoid spoil the experience.
@Jake, authentication is a requirement in almost any application so I think it is worth covering thoroughly. OmniAuth is one of the greatest things to happen in the Rails authentication space in a long time, and I wanted to show off how simple it can make authentication.
There is some overlap here with the earlier episodes because I want this screencast to stand on its own. Thanks for the input though, and expect some more variety in the future.
@0x4a6f4672, the reason there are so many authentication solutions is because different apps have different requirements. OmniAuth is a current favorite of mine because it stays out of the way and allows you to fully customize how authentication works in your app.
@Nate, yes, that is correct. If one has an account with Twitter and then signs in through Facebook it will make a separate account. Supporting multiple types of authentication per account helps this problem, but does not solve it completely. This is one of the primary drawbacks of offering third party authentication like this.
@Hubert, thanks for the suggestion. Testing is something I hope to cover more of in the future.
@ippa, the session is stored in a cookie by default, but it is encrypted and not editable by the user. However it is possible for him to see the contents of it, so just be certain to not put sensitive information that you don't want the user to see there. In this case it is okay if he sees his user id.
if session[:user_id] is a cookie wouldn't it be very easy to fake being whatever user?
@Antonio we all appreciate the high quality free screencasts, it's just there has been 3 OmniAuth screencasts in the past few weeks.
If you're looking for an example to use OmniAuth in Facebook/Sinatra applications here is a simple one I made for Heroku (heroku.com/facebook):
the code is here: http://bit.ly/faceboku
I think right now the code is not up to date in the Heroku site, but it is in github.
@Ryan can you please elaborate on how OmniAuth can work with Google API? for example access youtube data for uploading? Is there even a link between the two??
Your insight is much appreciated!
Ryan, I'm always looking forward to watching your screencasts.
I'd really appreciate an episode or two about TDD/BDD best practices, especially concerning integration of external services, so +1 Hubert.
Ryan, that's good as always.
However, with all those OmniAuth / social networking integration, I see on thing is missing from your screencasts: testing.
I am pretty sure that lots of people who want to integrate or base their authentication solutions on, say, Twitter, think "but how the hell I use that in Cucumber tests"?
Maybe it's worth creating a screencast about: how to integrate that sign, how to mock it or provite alternative sign in just for running tests -- creating "myapp-test" twitter account and using it to sign in is not only not fun but also slow and painful.
Amazing that you can pull off a reliable authentication solution is about 30 lines of code.
I'm creating a new application and after watching this I'm re-evaluating whether I need to have the user/password or whether I just want to go this route with simple authentication.
Thanks for doing this Ryan.
Q. You mentioned a few times that this method doesn't handle multiple authentications. Does that mean that each user can only use one authentication provider? I'm assuming so because the application obviously allows a choice of multiple authentication providers. What would happen if a user used Twitter and then tried to sign-in with Facebook? Would you get duplicate user accounts?
Hi ryan,
Nice and simpel. I think I'll be using this alot when Devise seems too much.
Cheers !