Hi there! I have 3 types of users in my system, And I''d like to redirect each of him for a differente page. I know Devise have a helper to do this, but I''m getting some problems to implement it I''m started trying from the documentation http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers In "class ApplicationController < ActionController::Base" def after_sign_in_path_for(resource) if resource.is_a?(User) && resource.can_publish? publisher_url else super endend But I''m get a error "undefined method `can_publish?'' for #<User:0x00000102f7a578>" I also tryed another examples who I found through google. But when I implement, nothing happens. I''m a bit lost for doing this. I''d like to put conditionals in controller to get a type from each user and redirect them for an especific page. For example if current_user.type == "Admin" redirect_to "http://example.com" end The question is: The place when I have to do this is really the application controler? And someone know any example who works correctly? thanks for help! -- *Fernando Aureliano* -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 8 June 2011 16:22, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> wrote:> Hi there! > I have 3 types of users in my system, And I''d like to redirect each of him > for a differente page. > I know Devise have a helper to do this, but I''m getting some problems to > implement it > I''m started trying from the documentation > http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers > In "class ApplicationController < ActionController::Base" > > def after_sign_in_path_for(resource) > if resource.is_a?(User) && resource.can_publish? > publisher_url > else > super > end > end > > But I''m get a error "undefined method `can_publish?'' for > #<User:0x00000102f7a578>"Have you provided a can_publish? method in the User model? Colin> I also tryed another examples who I found through google. But when I > implement, nothing happens. I''m a bit lost for doing this. > I''d like to put conditionals in controller to get a type from each user and > redirect them for an especific page. For example > if current_user.type == "Admin" > redirect_to "http://example.com" > end > > The question is: The place when I have to do this is really the application > controler? > And someone know any example who works correctly? > > thanks for help! > > -- > Fernando Aureliano > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I do not know this method, and the documentation does not show how to implement it. =( On Wed, Jun 8, 2011 at 12:30 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 8 June 2011 16:22, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> > wrote: > > Hi there! > > I have 3 types of users in my system, And I''d like to redirect each of > him > > for a differente page. > > I know Devise have a helper to do this, but I''m getting some problems to > > implement it > > I''m started trying from the documentation > > http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers > > In "class ApplicationController < ActionController::Base" > > > > def after_sign_in_path_for(resource) > > if resource.is_a?(User) && resource.can_publish? > > publisher_url > > else > > super > > end > > end > > > > But I''m get a error "undefined method `can_publish?'' for > > #<User:0x00000102f7a578>" > > Have you provided a can_publish? method in the User model? > > Colin > > > I also tryed another examples who I found through google. But when I > > implement, nothing happens. I''m a bit lost for doing this. > > I''d like to put conditionals in controller to get a type from each user > and > > redirect them for an especific page. For example > > if current_user.type == "Admin" > > redirect_to "http://example.com" > > end > > > > The question is: The place when I have to do this is really the > application > > controler? > > And someone know any example who works correctly? > > > > thanks for help! > > > > -- > > Fernando Aureliano > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- *Fernando Aureliano* -------------------------------------------------------------- [iOSDeveloper] - *ObjectiveC* [WebDesigner] - *CSS3&HTML5* *[WebDeveloper] - RubyOnRails* *-------------------------------------------------------------- * [portfolio] <http://www.fernandoaureliano.com> - [blog]<http://www.fernandoaureliano.com/> - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 8 June 2011 16:44, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> wrote:> I do not know this method, and the documentation does not show how to > implement it.In that case I think you are in need of some basic learning. I suggest you work through a tutorial such as railstutorial.org, which is free to use online, that should give you a better understanding of how to develop rails apps. Also have a look at the Rails Guides. Colin> > =( > > On Wed, Jun 8, 2011 at 12:30 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 8 June 2011 16:22, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> >> wrote: >> > Hi there! >> > I have 3 types of users in my system, And I''d like to redirect each of >> > him >> > for a differente page. >> > I know Devise have a helper to do this, but I''m getting some problems to >> > implement it >> > I''m started trying from the documentation >> > http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers >> > In "class ApplicationController < ActionController::Base" >> > >> > def after_sign_in_path_for(resource) >> > if resource.is_a?(User) && resource.can_publish? >> > publisher_url >> > else >> > super >> > end >> > end >> > >> > But I''m get a error "undefined method `can_publish?'' for >> > #<User:0x00000102f7a578>" >> >> Have you provided a can_publish? method in the User model? >> >> Colin >> >> > I also tryed another examples who I found through google. But when I >> > implement, nothing happens. I''m a bit lost for doing this. >> > I''d like to put conditionals in controller to get a type from each user >> > and >> > redirect them for an especific page. For example >> > if current_user.type == "Admin" >> > redirect_to "http://example.com" >> > end >> > >> > The question is: The place when I have to do this is really the >> > application >> > controler? >> > And someone know any example who works correctly? >> > >> > thanks for help! >> > >> > -- >> > Fernando Aureliano >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups >> > "Ruby on Rails: Talk" group. >> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group at >> > http://groups.google.com/group/rubyonrails-talk?hl=en. >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > > > -- > Fernando Aureliano > -------------------------------------------------------------- > [iOSDeveloper] - ObjectiveC > [WebDesigner] - CSS3&HTML5 > [WebDeveloper] - RubyOnRails > -------------------------------------------------------------- > [portfolio] - [blog] - [personal blog] - [twitter] > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi! Thanks by the tips! Actually I''m learning Rails, and I already see this tutorial, is very good. I''m already do too Rails for zoombies, Rails best pratices and a lot other tutorials. I''m doying my first web app, just to practice what I learned. but none of them learned about this method, and is the first time I am working with devise. I''m already work with anothers languages too. So, if anyone can help me with that, would be great. Thanks! On Wed, Jun 8, 2011 at 1:34 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 8 June 2011 16:44, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> > wrote: > > I do not know this method, and the documentation does not show how to > > implement it. > > In that case I think you are in need of some basic learning. I > suggest you work through a tutorial such as railstutorial.org, which > is free to use online, that should give you a better understanding of > how to develop rails apps. Also have a look at the Rails Guides. > > Colin > > > > > =( > > > > On Wed, Jun 8, 2011 at 12:30 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > >> > >> On 8 June 2011 16:22, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> > >> wrote: > >> > Hi there! > >> > I have 3 types of users in my system, And I''d like to redirect each > of > >> > him > >> > for a differente page. > >> > I know Devise have a helper to do this, but I''m getting some problems > to > >> > implement it > >> > I''m started trying from the documentation > >> > http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers > >> > In "class ApplicationController < ActionController::Base" > >> > > >> > def after_sign_in_path_for(resource) > >> > if resource.is_a?(User) && resource.can_publish? > >> > publisher_url > >> > else > >> > super > >> > end > >> > end > >> > > >> > But I''m get a error "undefined method `can_publish?'' for > >> > #<User:0x00000102f7a578>" > >> > >> Have you provided a can_publish? method in the User model? > >> > >> Colin > >> > >> > I also tryed another examples who I found through google. But when I > >> > implement, nothing happens. I''m a bit lost for doing this. > >> > I''d like to put conditionals in controller to get a type from each > user > >> > and > >> > redirect them for an especific page. For example > >> > if current_user.type == "Admin" > >> > redirect_to "http://example.com" > >> > end > >> > > >> > The question is: The place when I have to do this is really the > >> > application > >> > controler? > >> > And someone know any example who works correctly? > >> > > >> > thanks for help! > >> > > >> > -- > >> > Fernando Aureliano > >> > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups > >> > "Ruby on Rails: Talk" group. > >> > To post to this group, send email to > rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > To unsubscribe from this group, send email to > >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group at > >> > http://groups.google.com/group/rubyonrails-talk?hl=en. > >> > > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "Ruby on Rails: Talk" group. > >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> To unsubscribe from this group, send email to > >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> For more options, visit this group at > >> http://groups.google.com/group/rubyonrails-talk?hl=en. > >> > > > > > > > > -- > > Fernando Aureliano > > -------------------------------------------------------------- > > [iOSDeveloper] - ObjectiveC > > [WebDesigner] - CSS3&HTML5 > > [WebDeveloper] - RubyOnRails > > -------------------------------------------------------------- > > [portfolio] - [blog] - [personal blog] - [twitter] > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- *Fernando Aureliano* -------------------------------------------------------------- [iOSDeveloper] - *ObjectiveC* [WebDesigner] - *CSS3&HTML5* *[WebDeveloper] - RubyOnRails* *-------------------------------------------------------------- * [portfolio] <http://www.fernandoaureliano.com> - [blog]<http://www.fernandoaureliano.com/> - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jason Fleetwood-Boldt
2011-Jun-08 18:51 UTC
Re: I Can not redirect after login with Devise
Fernando, The problem is right in your code. Let me explain it to you, but I won''t offer a solution: def after_sign_in_path_for(resource) says if resource.is_a?(User) && resource.can_publish? We can tell from your code that you are passing in a User object (defined in app/models/user.rb) to this method. Whatever you had hoped this method would be doing, what it is doing is checking that object for the method can_publish? (note the question mark is part of the method name). The error tells you that you have no def can_publish? defined in your User model (app/models/user.rb) You must have written the after_sign_in_path_for() method at some point, or you copied it from somewhere. Take a step back and start writing some tests. If you go to call a method on a model (User), write a unit test for that method first. Then when you''re coding the after_sign_in_path_for() method don''t call any methods on object you haven''t written a unit test for. Then learn how to do functional & integration tests too. That''s your problem. Hope this helps.>> The question is: The place when I have to do this is really the >> >> > application >> >> > controler?The application controller is a fine place to do global (system-wide) checking of user privileges and logic around what happens to certain types of users at certain times. When you application grows larger, you can put these into a module and use include to mix these into your application controller. But that''s an advanced topic, what you''re doing is fine for now. You should also use existing gems like RESTful authentication for authentication if you are not. Checkout http://ruby-toolbox.com/ -- one of the things I like about this website is that gems get voted up & down so you see which ones are popular and can choose one that is widely adopted. Jason On Jun 8, 2011, at 2:28 PM, Fernando Aureliano wrote:> Hi! > > Thanks by the tips! > > Actually I''m learning Rails, and I already see this tutorial, is very good. > > I''m already do too Rails for zoombies, Rails best pratices and a lot other tutorials. > > I''m doying my first web app, just to practice what I learned. > > but none of them learned about this method, and is the first time I am working with devise. > > I''m already work with anothers languages too. > > So, if anyone can help me with that, would be great. > > Thanks! > > > > > On Wed, Jun 8, 2011 at 1:34 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > On 8 June 2011 16:44, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> wrote: > > I do not know this method, and the documentation does not show how to > > implement it. > > In that case I think you are in need of some basic learning. I > suggest you work through a tutorial such as railstutorial.org, which > is free to use online, that should give you a better understanding of > how to develop rails apps. Also have a look at the Rails Guides. > > Colin > > > > > =( > > > > On Wed, Jun 8, 2011 at 12:30 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> > >> On 8 June 2011 16:22, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> > >> wrote: > >> > Hi there! > >> > I have 3 types of users in my system, And I''d like to redirect each of > >> > him > >> > for a differente page. > >> > I know Devise have a helper to do this, but I''m getting some problems to > >> > implement it > >> > I''m started trying from the documentation > >> > http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers > >> > In "class ApplicationController < ActionController::Base" > >> > > >> > def after_sign_in_path_for(resource) > >> > if resource.is_a?(User) && resource.can_publish? > >> > publisher_url > >> > else > >> > super > >> > end > >> > end > >> > > >> > But I''m get a error "undefined method `can_publish?'' for > >> > #<User:0x00000102f7a578>" > >> > >> Have you provided a can_publish? method in the User model? > >> > >> Colin > >> > >> > I also tryed another examples who I found through google. But when I > >> > implement, nothing happens. I''m a bit lost for doing this. > >> > I''d like to put conditionals in controller to get a type from each user > >> > and > >> > redirect them for an especific page. For example > >> > if current_user.type == "Admin" > >> > redirect_to "http://example.com" > >> > end > >> > > >> > The question is: The place when I have to do this is really the > >> > application > >> > controler? > >> > And someone know any example who works correctly? > >> > > >> > thanks for help! > >> > > >> > -- > >> > Fernando Aureliano > >> > > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups > >> > "Ruby on Rails: Talk" group. > >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group at > >> > http://groups.google.com/group/rubyonrails-talk?hl=en. > >> > > >> > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "Ruby on Rails: Talk" group. > >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. > >> To unsubscribe from this group, send email to > >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> For more options, visit this group at > >> http://groups.google.com/group/rubyonrails-talk?hl=en. > >> > > > > > > > > -- > > Fernando Aureliano > > -------------------------------------------------------------- > > [iOSDeveloper] - ObjectiveC > > [WebDesigner] - CSS3&HTML5 > > [WebDeveloper] - RubyOnRails > > -------------------------------------------------------------- > > [portfolio] - [blog] - [personal blog] - [twitter] > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > -- > Fernando Aureliano > -------------------------------------------------------------- > [iOSDeveloper] - ObjectiveC > [WebDesigner] - CSS3&HTML5 > [WebDeveloper] - RubyOnRails > -------------------------------------------------------------- > [portfolio] - [blog] - [personal blog] - [twitter] > > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This helps a lot. Thanks! On Wed, Jun 8, 2011 at 3:51 PM, Jason Fleetwood-Boldt <tech-eJ8lBn5LdNBhbmWW9KSYcQ@public.gmane.org>wrote:> Fernando, > > The problem is right in your code. > > Let me explain it to you, but I won''t offer a solution: > > def after_sign_in_path_for(resource) says if resource.is_a?(User) && > resource.can_publish? > > We can tell from your code that you are passing in a User object (defined > in app/models/user.rb) to this method. Whatever you *had** **hoped* this > method would be doing, *what it is doing is* checking that object for the > method can_publish? (note the question mark is part of the method name). > > The error tells you that you have no *def can_publish?* defined in your > User model (app/models/user.rb) > > You must have written the after_sign_in_path_for() method at some point, or > you copied it from somewhere. > > Take a step back and start writing some tests. If you go to call a method > on a model (User), write a unit test for that method first. Then when you''re > coding the after_sign_in_path_for() method don''t call any methods on object > you haven''t written a unit test for. Then learn how to do functional & > integration tests too. > > That''s your problem. Hope this helps. > > > The question is: The place when I have to do this is really the >> >> > application >> >> > controler? >> > > > The application controller is a fine place to do global (system-wide) > checking of user privileges and logic around what happens to certain types > of users at certain times. When you application grows larger, you can put > these into a module and use include to mix these into your application > controller. But that''s an advanced topic, what you''re doing is fine for > now. > > You should also use existing gems like RESTful authentication for > authentication if you are not. Checkout http://ruby-toolbox.com/ -- one of > the things I like about this website is that gems get voted up & down so you > see which ones are popular and can choose one that is widely adopted. > > Jason > > > On Jun 8, 2011, at 2:28 PM, Fernando Aureliano wrote: > > Hi! > > Thanks by the tips! > > Actually I''m learning Rails, and I already see this tutorial, is very good. > > > I''m already do too Rails for zoombies, Rails best pratices and a lot other > tutorials. > > > I''m doying my first web app, just to practice what I learned. > > > but none of them learned about this method, and is the first time I am > working with devise. > > > I''m already work with anothers languages too. > > > So, if anyone can help me with that, would be great. > > > Thanks! > > > > > On Wed, Jun 8, 2011 at 1:34 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 8 June 2011 16:44, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> >> wrote: >> > I do not know this method, and the documentation does not show how to >> > implement it. >> >> In that case I think you are in need of some basic learning. I >> suggest you work through a tutorial such as railstutorial.org, which >> is free to use online, that should give you a better understanding of >> how to develop rails apps. Also have a look at the Rails Guides. >> >> Colin >> >> > >> > =( >> > >> > On Wed, Jun 8, 2011 at 12:30 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> >> wrote: >> >> >> >> On 8 June 2011 16:22, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> >> >> wrote: >> >> > Hi there! >> >> > I have 3 types of users in my system, And I''d like to redirect each >> of >> >> > him >> >> > for a differente page. >> >> > I know Devise have a helper to do this, but I''m getting some problems >> to >> >> > implement it >> >> > I''m started trying from the documentation >> >> > http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers >> >> > In "class ApplicationController < ActionController::Base" >> >> > >> >> > def after_sign_in_path_for(resource) >> >> > if resource.is_a?(User) && resource.can_publish? >> >> > publisher_url >> >> > else >> >> > super >> >> > end >> >> > end >> >> > >> >> > But I''m get a error "undefined method `can_publish?'' for >> >> > #<User:0x00000102f7a578>" >> >> >> >> Have you provided a can_publish? method in the User model? >> >> >> >> Colin >> >> >> >> > I also tryed another examples who I found through google. But when I >> >> > implement, nothing happens. I''m a bit lost for doing this. >> >> > I''d like to put conditionals in controller to get a type from each >> user >> >> > and >> >> > redirect them for an especific page. For example >> >> > if current_user.type == "Admin" >> >> > redirect_to "http://example.com" >> >> > end >> >> > >> >> > The question is: The place when I have to do this is really the >> >> > application >> >> > controler? >> >> > And someone know any example who works correctly? >> >> > >> >> > thanks for help! >> >> > >> >> > -- >> >> > Fernando Aureliano >> >> > >> >> > -- >> >> > You received this message because you are subscribed to the Google >> >> > Groups >> >> > "Ruby on Rails: Talk" group. >> >> > To post to this group, send email to >> rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > To unsubscribe from this group, send email to >> >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > For more options, visit this group at >> >> > http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups >> >> "Ruby on Rails: Talk" group. >> >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> . >> >> To unsubscribe from this group, send email to >> >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> For more options, visit this group at >> >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >> > >> > >> > >> > -- >> > Fernando Aureliano >> > -------------------------------------------------------------- >> > [iOSDeveloper] - ObjectiveC >> > [WebDesigner] - CSS3&HTML5 >> > [WebDeveloper] - RubyOnRails >> > -------------------------------------------------------------- >> > [portfolio] - [blog] - [personal blog] - [twitter] >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "Ruby on Rails: Talk" group. >> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > To unsubscribe from this group, send email to >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group at >> > http://groups.google.com/group/rubyonrails-talk?hl=en. >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > *Fernando Aureliano* > -------------------------------------------------------------- > [iOSDeveloper] - *ObjectiveC* > [WebDesigner] - *CSS3&HTML5* > *[WebDeveloper] - RubyOnRails* > *-------------------------------------------------------------- > * > [portfolio] <http://www.fernandoaureliano.com/> - [blog]<http://www.fernandoaureliano.com/> > - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- *Fernando Aureliano* -------------------------------------------------------------- [iOSDeveloper] - *ObjectiveC* [WebDesigner] - *CSS3&HTML5* *[WebDeveloper] - RubyOnRails* *-------------------------------------------------------------- * [portfolio] <http://www.fernandoaureliano.com> - [blog]<http://www.fernandoaureliano.com/> - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Get it to work! =D private def stored_location_for(resource_or_scope) nil end def after_sign_in_path_for(resource_or_scope) "http://example.com" end Thanks by the tips! ;) On Wed, Jun 8, 2011 at 3:55 PM, Fernando Aureliano < mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> wrote:> This helps a lot. > > Thanks! > > > On Wed, Jun 8, 2011 at 3:51 PM, Jason Fleetwood-Boldt < > tech-eJ8lBn5LdNBhbmWW9KSYcQ@public.gmane.org> wrote: > >> Fernando, >> >> The problem is right in your code. >> >> Let me explain it to you, but I won''t offer a solution: >> >> def after_sign_in_path_for(resource) says if resource.is_a?(User) && >> resource.can_publish? >> >> We can tell from your code that you are passing in a User object (defined >> in app/models/user.rb) to this method. Whatever you *had** **hoped* this >> method would be doing, *what it is doing is* checking that object for the >> method can_publish? (note the question mark is part of the method name). >> >> The error tells you that you have no *def can_publish?* defined in your >> User model (app/models/user.rb) >> >> You must have written the after_sign_in_path_for() method at some point, >> or you copied it from somewhere. >> >> Take a step back and start writing some tests. If you go to call a method >> on a model (User), write a unit test for that method first. Then when you''re >> coding the after_sign_in_path_for() method don''t call any methods on object >> you haven''t written a unit test for. Then learn how to do functional & >> integration tests too. >> >> That''s your problem. Hope this helps. >> >> >> The question is: The place when I have to do this is really the >>> >> > application >>> >> > controler? >>> >> >> >> The application controller is a fine place to do global (system-wide) >> checking of user privileges and logic around what happens to certain types >> of users at certain times. When you application grows larger, you can put >> these into a module and use include to mix these into your application >> controller. But that''s an advanced topic, what you''re doing is fine for >> now. >> >> You should also use existing gems like RESTful authentication for >> authentication if you are not. Checkout http://ruby-toolbox.com/ -- one >> of the things I like about this website is that gems get voted up & down so >> you see which ones are popular and can choose one that is widely adopted. >> >> Jason >> >> >> On Jun 8, 2011, at 2:28 PM, Fernando Aureliano wrote: >> >> Hi! >> >> Thanks by the tips! >> >> Actually I''m learning Rails, and I already see this tutorial, is very >> good. >> >> >> I''m already do too Rails for zoombies, Rails best pratices and a lot other >> tutorials. >> >> >> I''m doying my first web app, just to practice what I learned. >> >> >> but none of them learned about this method, and is the first time I am >> working with devise. >> >> >> I''m already work with anothers languages too. >> >> >> So, if anyone can help me with that, would be great. >> >> >> Thanks! >> >> >> >> >> On Wed, Jun 8, 2011 at 1:34 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >>> On 8 June 2011 16:44, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> >>> wrote: >>> > I do not know this method, and the documentation does not show how to >>> > implement it. >>> >>> In that case I think you are in need of some basic learning. I >>> suggest you work through a tutorial such as railstutorial.org, which >>> is free to use online, that should give you a better understanding of >>> how to develop rails apps. Also have a look at the Rails Guides. >>> >>> Colin >>> >>> > >>> > =( >>> > >>> > On Wed, Jun 8, 2011 at 12:30 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> >>> wrote: >>> >> >>> >> On 8 June 2011 16:22, Fernando Aureliano <mail-7WGqr3rU1tU38Fpv8Ij67aBKnGwkPULj@public.gmane.org> >>> >> wrote: >>> >> > Hi there! >>> >> > I have 3 types of users in my system, And I''d like to redirect each >>> of >>> >> > him >>> >> > for a differente page. >>> >> > I know Devise have a helper to do this, but I''m getting some >>> problems to >>> >> > implement it >>> >> > I''m started trying from the documentation >>> >> > http://rubydoc.info/gems/devise/1.1.2/Devise/Controllers/Helpers >>> >> > In "class ApplicationController < ActionController::Base" >>> >> > >>> >> > def after_sign_in_path_for(resource) >>> >> > if resource.is_a?(User) && resource.can_publish? >>> >> > publisher_url >>> >> > else >>> >> > super >>> >> > end >>> >> > end >>> >> > >>> >> > But I''m get a error "undefined method `can_publish?'' for >>> >> > #<User:0x00000102f7a578>" >>> >> >>> >> Have you provided a can_publish? method in the User model? >>> >> >>> >> Colin >>> >> >>> >> > I also tryed another examples who I found through google. But when I >>> >> > implement, nothing happens. I''m a bit lost for doing this. >>> >> > I''d like to put conditionals in controller to get a type from each >>> user >>> >> > and >>> >> > redirect them for an especific page. For example >>> >> > if current_user.type == "Admin" >>> >> > redirect_to "http://example.com" >>> >> > end >>> >> > >>> >> > The question is: The place when I have to do this is really the >>> >> > application >>> >> > controler? >>> >> > And someone know any example who works correctly? >>> >> > >>> >> > thanks for help! >>> >> > >>> >> > -- >>> >> > Fernando Aureliano >>> >> > >>> >> > -- >>> >> > You received this message because you are subscribed to the Google >>> >> > Groups >>> >> > "Ruby on Rails: Talk" group. >>> >> > To post to this group, send email to >>> rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> >> > To unsubscribe from this group, send email to >>> >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> >> > For more options, visit this group at >>> >> > http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> > >>> >> >>> >> -- >>> >> You received this message because you are subscribed to the Google >>> Groups >>> >> "Ruby on Rails: Talk" group. >>> >> To post to this group, send email to >>> rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> >> To unsubscribe from this group, send email to >>> >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> >> For more options, visit this group at >>> >> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> >>> > >>> > >>> > >>> > -- >>> > Fernando Aureliano >>> > -------------------------------------------------------------- >>> > [iOSDeveloper] - ObjectiveC >>> > [WebDesigner] - CSS3&HTML5 >>> > [WebDeveloper] - RubyOnRails >>> > -------------------------------------------------------------- >>> > [portfolio] - [blog] - [personal blog] - [twitter] >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> Groups >>> > "Ruby on Rails: Talk" group. >>> > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >>> . >>> > To unsubscribe from this group, send email to >>> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> > For more options, visit this group at >>> > http://groups.google.com/group/rubyonrails-talk?hl=en. >>> > >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >>> >> >> >> -- >> *Fernando Aureliano* >> -------------------------------------------------------------- >> [iOSDeveloper] - *ObjectiveC* >> [WebDesigner] - *CSS3&HTML5* >> *[WebDeveloper] - RubyOnRails* >> *-------------------------------------------------------------- >> * >> [portfolio] <http://www.fernandoaureliano.com/> - [blog]<http://www.fernandoaureliano.com/> >> - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > > > -- > *Fernando Aureliano* > -------------------------------------------------------------- > [iOSDeveloper] - *ObjectiveC* > [WebDesigner] - *CSS3&HTML5* > *[WebDeveloper] - RubyOnRails* > *-------------------------------------------------------------- > * > [portfolio] <http://www.fernandoaureliano.com> - [blog]<http://www.fernandoaureliano.com/> > - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> > >-- *Fernando Aureliano* -------------------------------------------------------------- [iOSDeveloper] - *ObjectiveC* [WebDesigner] - *CSS3&HTML5* *[WebDeveloper] - RubyOnRails* *-------------------------------------------------------------- * [portfolio] <http://www.fernandoaureliano.com> - [blog]<http://www.fernandoaureliano.com/> - [personal blog] <http://www.obsessivocompulsivo.com/> - [twitter]<http://twitter.com/Pailoro> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.