Howdy. Is it possible in Rails to make www.mysite.com/anyname result in a page displayed that is essentially a custom "about me" portal page for a user? For example, user bob exists in the database, so I want www.mysite.com/bob to show a bob-specific page (without authentication, or rather allowing anyone to see). I''ve done this in JSP using a custom 404 page that redirects to www.mysite.com/main.jsp?portal=bob. While not elegant, it works well. Is there a way (and better yet, an elegant way) to do this in Rails? Thanks! Michael
Hello Michael, Michael Teter said the following on 2005-08-29 12:52:> I''ve done this in JSP using a custom 404 page that redirects to > www.mysite.com/main.jsp?portal=bob. While not elegant, it works well. > > Is there a way (and better yet, an elegant way) to do this in Rails?Read all about routes: "Routing: Native Ruby Rewriting" http://manuals.rubyonrails.com/read/book/9 BTW, there isn''t there any API documentation on Routing ? Can''t find anything on api.rubyonrails.com ? Bye ! François
Wow! Simple! Fantastic. As another Michael pointed out, some listbound messages seem to be really delayed... is that normal? I don''t remember my replies to topics in the past being so delayed. On 8/30/05, Matt Jankowski <mjankowski-3V1LzDqIiU+4+7hldlPAjkEOCMrvLtNR@public.gmane.org > wrote:> > Routes. > > In this case, something like: > > map.connect '':username'', :controller => ''users'', :action => ''user'' > > Which will send www.site.com/bob <http://www.site.com/bob> to the ''users'' > control and ''user'' > action, as well as making params[:username] hold ''bob''. > > At that point you can do a User.find_by_username (params[:username]) from > w/in the controller. > > -matt > > > > Michael Teter wrote: > > Howdy. > > > > Is it possible in Rails to make www.mysite.com/anyname > <http://www.mysite.com/anyname> result in a > > page displayed that is essentially a custom "about me" portal page for > > a user? > > > > For example, user bob exists in the database, so I want > > www.mysite.com/bob <http://www.mysite.com/bob> to show a bob-specific > page (without > > authentication, or rather allowing anyone to see). > > > > I''ve done this in JSP using a custom 404 page that redirects to > > www.mysite.com/main.jsp?portal=bob<http://www.mysite.com/main.jsp?portal=bob>. > While not elegant, it works well. > > > > Is there a way (and better yet, an elegant way) to do this in Rails? > > > > Thanks! > > Michael > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Here''s a solution for your issue, which is a lot more elegant than using a 404 :) - Add this line to config/routes.rb map.connect '':user'', :controller => "user_home", :action => "index" - Use the user variable in your controller def index render_text "home for #{@params[:user]}" end - Go to http://localhost:3000/dude Cheers, Cloves --- Michael Teter <michael.teter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Howdy. > > Is it possible in Rails to make > www.mysite.com/anyname result in a > page displayed that is essentially a custom "about > me" portal page for > a user? > > For example, user bob exists in the database, so I > want > www.mysite.com/bob to show a bob-specific page > (without > authentication, or rather allowing anyone to see). > > I''ve done this in JSP using a custom 404 page that > redirects to > www.mysite.com/main.jsp?portal=bob. While not > elegant, it works well. > > Is there a way (and better yet, an elegant way) to > do this in Rails? > > Thanks! > Michael > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On 8/29/05, Michael Teter <michael.teter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Howdy. > > Is it possible in Rails to make www.mysite.com/anyname result in a > page displayed that is essentially a custom "about me" portal page for > a user? > > For example, user bob exists in the database, so I want > www.mysite.com/bob to show a bob-specific page (without > authentication, or rather allowing anyone to see). > > I''ve done this in JSP using a custom 404 page that redirects to > www.mysite.com/main.jsp?portal=bob. While not elegant, it works well. > > Is there a way (and better yet, an elegant way) to do this in Rails? > > Thanks! > Michael > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Take a look at routes: http://manuals.rubyonrails.com/read/chapter/65 -- - Mik Mifflin "Whether freedom is going to survive at all is in doubt, but we''ve got to try" - RMS
On 29 Aug 2005, at 17:52, Michael Teter wrote:> Is it possible in Rails to make www.mysite.com/anyname result in a > page displayed that is essentially a custom "about me" portal page for > a user? > > For example, user bob exists in the database, so I want > www.mysite.com/bob to show a bob-specific page (without > authentication, or rather allowing anyone to see). > > I''ve done this in JSP using a custom 404 page that redirects to > www.mysite.com/main.jsp?portal=bob. While not elegant, it works well. > > Is there a way (and better yet, an elegant way) to do this in Rails?<Newbie alert> It seems to me to be rather easy - but perhaps not elegant enough to do as follows: 1. Store your users in a DB table (or other format, should a DB not be good for you) and create your User model. 2. Create a Controller (about_controller.rb) with an index method that loads the user info based on the username given in the url. - make sure you secure the controller properly with validations. (maybe even a whitelist) 3. Create a new entry in config/routes.rb something along these lines (NB!! dependant on other urls/routes on your system) map.about '':name'', :controller => ''about'', :action => ''index'' Hope I haven''t made any big errors there. If so, please forgive me, I''m learning too ;-) </Newbie alert> Kind regards, Mats ---- "TextMate, coding with an incredible sense of joy and ease" - www.macromates.com -
On 8/29/05, Michael Teter <michael.teter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is it possible in Rails to make www.mysite.com/anyname result in a > page displayed that is essentially a custom "about me" portal page for > a user?This is easy... first you make a controller/action that displays the information you like... whatever information about the user that you want... just like you do with templates for any other action. Then you make a route that redirects the URLs you want to that controller/action. -- Urban Artography http://artography.ath.cx
On Aug 29, 2005, at 9:52 AM, Michael Teter wrote:> Howdy. > > Is it possible in Rails to make www.mysite.com/anyname result in a > page displayed that is essentially a custom "about me" portal page for > a user? > > For example, user bob exists in the database, so I want > www.mysite.com/bob to show a bob-specific page (without > authentication, or rather allowing anyone to see). > > I''ve done this in JSP using a custom 404 page that redirects to > www.mysite.com/main.jsp?portal=bob. While not elegant, it works well. > > Is there a way (and better yet, an elegant way) to do this in Rails? > > Thanks! > Michael > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Michael- You could do it with a custom route and a dispatch method like this: map.connect '':username'', :controller => "user_page", :action => "dispatch" Then in user_page_controller.rb def dispatch @content = UserInfo.find_by_user(params[:username]) end I''d probably put the :username route near the bottom of the list of routes so other routes don''t trigger it. Hope that helps- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
On 8/29/05, Michael Teter <michael.teter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Is it possible in Rails to make www.mysite.com/anyname<http://www.mysite.com/anyname>result in a > page displayed that is essentially a custom "about me" portal page for > a user?You can probably just use routes for this, depending on how complex the application is. I''ve done something similar for mapping page titles to the root of the path like what you describe. Use a route something like this: map.connect "/:name", :controller => "person", :action => "show" And an action something like this: def show @person = Person.find_by_name(param[:name]) end The problematic part is the routing. When you create a route like the above, it will gladly match anything and everything unless you are careful about what you''re doing, which inevitably breaks stuff. The way I mitigate this is to create a route before the greedy one that specifically matches the controllers that the app uses, and a route afterward to specifically match the index action. My app is pretty simple, and the routes end up looking like this: map.connect ''/page/:action/:id'', :controller => ''page'' map.connect '':title'', :controller => ''page'', :action => ''view'' map.connect '''', :controller => ''page'', :action => ''index'' -- Nick Zadrozny <nick-vwIjNL0M3i9Wk0Htik3J/w@public.gmane.org> _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 30/08/2005, at 1:52 AM, Michael Teter wrote:> Howdy. > > Is it possible in Rails to make www.mysite.com/anyname result in a > page displayed that is essentially a custom "about me" portal page for > a user? > > For example, user bob exists in the database, so I want > www.mysite.com/bob to show a bob-specific page (without > authentication, or rather allowing anyone to see).I did this on a really basic CMS, i have a route like map.connect ''/:name'', :controller => "page", :action => "view", : name => "home" and then in the controller something like page = Page.find_by_name params[:name] is this what you were after?
Look into routes (which are kept in config/routes.rb, and well documented on the web). What you are wanting is a route with a single component, which validates by checking the User model, and goes to the controller of your choice. In other words, if you have a "tell" controller that has an "about" method you just want to make "mysite.com/:name" route to the ":controller => "tell", :action => "about" the same way "mysite.com/tell/about/:name" would by default. --MarkusQ On Mon, 2005-08-29 at 10:52, Michael Teter wrote:> Howdy. > > Is it possible in Rails to make www.mysite.com/anyname result in a > page displayed that is essentially a custom "about me" portal page for > a user? > > For example, user bob exists in the database, so I want > www.mysite.com/bob to show a bob-specific page (without > authentication, or rather allowing anyone to see). > > I''ve done this in JSP using a custom 404 page that redirects to > www.mysite.com/main.jsp?portal=bob. While not elegant, it works well. > > Is there a way (and better yet, an elegant way) to do this in Rails? > > Thanks! > Michael > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks to everyone for the great responses. Please, no more cards and letters! (joke) Anyway, I''m going to the beach, without a computer, so I''ll try these suggestions when I get back :) On 8/30/05, Cloves Carneiro Junior <ccarneiroj-FFYn/CNdgSA@public.gmane.org> wrote:> Hi > > Here''s a solution for your issue, which is a lot more > elegant than using a 404 :) > > - Add this line to config/routes.rb > map.connect '':user'', :controller => "user_home", > :action => "index" > - Use the user variable in your controller > def index > render_text "home for #{@params[:user]}" > end > - Go to http://localhost:3000/dude > > Cheers, > > Cloves > > --- Michael Teter <michael.teter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Howdy. > > > > Is it possible in Rails to make > > www.mysite.com/anyname result in a > > page displayed that is essentially a custom "about > > me" portal page for > > a user? > > > > For example, user bob exists in the database, so I > > want > > www.mysite.com/bob to show a bob-specific page > > (without > > authentication, or rather allowing anyone to see). > > > > I''ve done this in JSP using a custom 404 page that > > redirects to > > www.mysite.com/main.jsp?portal=bob. While not > > elegant, it works well. > > > > Is there a way (and better yet, an elegant way) to > > do this in Rails? > > > > Thanks! > > Michael > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >