Hello, I''m trying to do develop some modules so I can reuse all my codes in different projects. I need to put routing in different files, and in route.rb include the files which have my routing code, but I don''t know if this would work, and if I could actually do it? any help would be good :) Example, this one should be for the account model, are in route_account.rb. map.login ''login'', :controller => ''accounts'', :action => ''login'' map.login ''signup'', :controller => ''accounts'', :action => ''signup'' map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' map.account ''account'' :controller => ''accounts'', :action => ''account'' How can I include the following line in route.rb? Regards, Jamal Thanks for your help! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wrap those route definitions in a method and voila! # lib/routes_account.rb... module RouteAccount def add_routes_to(map) map.login ''login'', :controller => ''accounts'', :action => ''login'' # I presume the next one should actually be map.signup, not map.login... map.login ''signup'', :controller => ''accounts'', :action => ''signup'' map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' map.account ''account'' :controller => ''accounts'', :action => ''account'' end end # config/routes.rb... ActionController::Routing::Routes.draw do |map| # I found that I had problems loading the routes if I didn''t load them first. YMMV RouteAccount.add_routes_to map rescue nil # Continue normal routing... end RSL On 3/27/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, > > I''m trying to do develop some modules so I can reuse all my codes in > different projects. > > I need to put routing in different files, and in route.rb include the > files which have my routing code, but I don''t know if this would work, > and if I could actually do it? any help would be good :) > > Example, this one should be for the account model, are in > route_account.rb. > > map.login ''login'', :controller => ''accounts'', :action => ''login'' > map.login ''signup'', :controller => ''accounts'', :action => ''signup'' > map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' > map.account ''account'' :controller => ''accounts'', :action => ''account'' > > How can I include the following line in route.rb? > > Regards, > Jamal > > Thanks for your help! > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Obviously, that should be a class method! Oops. That''s what I get for typing rather than cutting and pasting from my app. RSL On 3/27/07, Russell Norris <rsl-ftMzyaTR+bHNyFkoKTPOtdi2O/JbrIOy@public.gmane.org> wrote:> > Wrap those route definitions in a method and voila! > > # lib/routes_account.rb... > module RouteAccount > def add_routes_to(map) > map.login ''login'', :controller => ''accounts'', :action => ''login'' > # I presume the next one should actually be map.signup, not > map.login... > map.login ''signup'', :controller => ''accounts'', :action => ''signup'' > map.logout ''logout'', :controller => ''accounts'', :action => > ''logout'' > map.account ''account'' :controller => ''accounts'', :action => ''account'' > end > end > > # config/routes.rb... > ActionController::Routing::Routes.draw do |map| > # I found that I had problems loading the routes if I didn''t load them > first. YMMV > RouteAccount.add_routes_to map rescue nil > > # Continue normal routing... > end > > RSL > On 3/27/07, Jamal Soueidan < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > > Hello, > > > > I''m trying to do develop some modules so I can reuse all my codes in > > different projects. > > > > I need to put routing in different files, and in route.rb include the > > files which have my routing code, but I don''t know if this would work, > > and if I could actually do it? any help would be good :) > > > > Example, this one should be for the account model, are in > > route_account.rb. > > > > map.login ''login'', :controller => ''accounts'', :action => ''login'' > > map.login ''signup'', :controller => ''accounts'', :action => ''signup'' > > map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' > > map.account ''account'' :controller => ''accounts'', :action => ''account'' > > > > How can I include the following line in route.rb? > > > > Regards, > > Jamal > > > > Thanks for your help! > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> Wrap those route definitions in a method and voila! > > # lib/routes_account.rb... > module RouteAccount > end > > RSLWeird, its not working, I pasted this in the route.rb RouteAccount.add_routes_to(map) rescue nil and then I created a file "route_account", and insert this into it Module RouteAccount def add_routes_to(map) map.login ''login'', :controller => ''user'', :action => ''login'' map.login ''signup'', :controller => ''user'', :action => ''signup'' map.logout ''logout'', :controller => ''user'', :action => ''logout'' map.account ''account'', :controller => ''user'', :action => ''account'' end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What error is it giving you? Is it saying it doesn''t have a constant RouteAccount? RSL On 3/27/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Russell Norris wrote: > > Wrap those route definitions in a method and voila! > > > > # lib/routes_account.rb... > > module RouteAccount > > end > > > > RSL > > Weird, its not working, I pasted this in the route.rb > > RouteAccount.add_routes_to(map) rescue nil > > and then I created a file "route_account", and insert this into it > > Module RouteAccount > > def add_routes_to(map) > > map.login ''login'', > :controller => ''user'', > :action => ''login'' > > map.login ''signup'', > :controller => ''user'', > :action => ''signup'' > > map.logout ''logout'', > :controller => ''user'', > :action => ''logout'' > > map.account ''account'', > :controller => ''user'', > :action => ''account'' > end > > end > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Module RouteAccount to class RouteAccount is not working either :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I just caught that class/module error too. What error _are_ you getting though? RSL On 3/27/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Module RouteAccount to class RouteAccount is not working either :( > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan wrote:> Module RouteAccount to class RouteAccount is not working either :(undefine method when using both module and class...I think I should "require" somewhere the file? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan wrote:> Jamal Soueidan wrote: >> Module RouteAccount to class RouteAccount is not working either :( > > undefine method when using both module and class...I think I should > "require" somewhere the file?I tried to write require ''lib/route_account'' in the top route.rb that didnt work either.... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It''s seeing the class, just not the method. Perhaps you missed my email about making the method a class method instead of a instance one. :) Chalk all my forgetful little errors this morning to lack of coffee. Or something. RSL On 3/27/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Jamal Soueidan wrote: > > Jamal Soueidan wrote: > >> Module RouteAccount to class RouteAccount is not working either :( > > > > undefine method when using both module and class...I think I should > > "require" somewhere the file? > > I tried to write > > require ''lib/route_account'' > > in the top route.rb that didnt work either.... > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> It''s seeing the class, just not the method. Perhaps you missed my email > about making the method a class method instead of a instance one. :) > Chalk > all my forgetful little errors this morning to lack of coffee. Or > something. > > RSLmodule RouteAccount class RouteAccount def add_routes_to(map) map.login ''login'', :controller => ''user'', :action => ''login'' map.signup ''signup'', :controller => ''user'', :action => ''signup'' map.logout ''logout'', :controller => ''user'', :action => ''logout'' map.account ''account'', :controller => ''user'', :action => ''account'' end end end like this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry I wasn''t clearer. class RouteAccount def self.add_routes_to(map) map.login ''login'', :controller => ''accounts'', :action => ''login'' # I presume the next one should actually be map.signup, not map.login... map.login ''signup'', :controller => ''accounts'', :action => ''signup'' map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' map.account ''account'' :controller => ''accounts'', :action => ''account'' end end Like _that_. On 3/27/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Russell Norris wrote: > > It''s seeing the class, just not the method. Perhaps you missed my email > > about making the method a class method instead of a instance one. :) > > Chalk > > all my forgetful little errors this morning to lack of coffee. Or > > something. > > > > RSL > > module RouteAccount > > class RouteAccount > > def add_routes_to(map) > > map.login ''login'', > :controller => ''user'', > :action => ''login'' > > map.signup ''signup'', > :controller => ''user'', > :action => ''signup'' > > map.logout ''logout'', > :controller => ''user'', > :action => ''logout'' > > map.account ''account'', > :controller => ''user'', > :action => ''account'' > end > end > > end > > like this? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> Sorry I wasn''t clearer. > > class RouteAccount > def self.add_routes_to(map) > map.login ''login'', :controller => ''accounts'', :action => ''login'' > # I presume the next one should actually be map.signup, not .Not working either, I don''t think it will work, I tried everything? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Not only does it work but I''ve got two variations of it working in my app. If you''d like, I can help you more but not if you''re insistent on telling me that it doesn''t work. RSL On 3/28/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Russell Norris wrote: > > Sorry I wasn''t clearer. > > > > class RouteAccount > > def self.add_routes_to(map) > > map.login ''login'', :controller => ''accounts'', :action => ''login'' > > # I presume the next one should actually be map.signup, not . > > Not working either, I don''t think it will work, I tried everything? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Russell Norris wrote:> Not only does it work but I''ve got two variations of it working in my > app. > If you''d like, I can help you more but not if you''re insistent on > telling me > that it doesn''t work. > > RSLWell I''m sorry, I still don''t get it to work :( Routing Error no route found to match "/login" with {:method=>:get} Can you sent me your files, so I can just replace them with what I have? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
No, I cannot just send you my files. Heh. However. I''m more than willing to go over [in one email] what I''ve suggested you do. 1. Create the file in lib/route_account.rb 2. Create the class [not module as I mistakenly first said] RouteAccount and a class method add_routes_to... class RouteAccount # Make sure this is self.add_routes_to(map) def self.add_routes_to(map) map.login ''login'', :controller => ''accounts'', :action => ''login'' map.signup ''signup'', :controller => ''accounts'', :action => ''signup'' map.logout ''logout'', :controller => ''accounts'', :action => ''logout'' map.account ''account'' :controller => ''accounts'', :action => ''account'' end end 3. In your config/routes.rb, call this method before you set the normal routes... ActionController::Routing::Routes.draw do |map| RouteAccount.add_routes_to map # Just like that. # Then add your other routes here end 4. At the end of the routes.rb file [AFTER you close the routes.draw block] you can add the line: ActionController::Routing::Routes.routes.each{|r| puts r} which will output a listing of all the routes to the terminal you started your server from. You''ll want to comment that out in production mode of course. All this code does is take the route map that the Routes.draw creates/uses and sends it to a class method which adds routes to it. Nothing weird. Just a different place than normally routes are set. I got the idea from looking around Mephisto''s source. Rick is so far above me as a programmer that my implementation is a lot simpler but basically the same. RSL On 3/29/07, Jamal Soueidan <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Russell Norris wrote: > > Not only does it work but I''ve got two variations of it working in my > > app. > > If you''d like, I can help you more but not if you''re insistent on > > telling me > > that it doesn''t work. > > > > RSL > > Well I''m sorry, I still don''t get it to work :( > > Routing Error > no route found to match "/login" with {:method=>:get} > > Can you sent me your files, so I can just replace them with what I have? > > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---