Though the router is absolutely Ruby, and you can do very Ruby things
there, bare in mind that it's Ruby that gets loaded on each request,
so don't get to fancy.  I've seen an anti-patern several times now
where route files are either very complex or meta-programmed and
caused some very odd behavior or memory leaks.

I'm not saying not to program it, just saying to keep it as simple as possible.

Best,
Rob

On Tue, Oct 27, 2009 at 18:01, Erik Pukinskis <[email protected]> wrote:
>
> Martin,
>
> Yeah, that helps a lot.  I have to remember that the routes generator
> is just Ruby and I can do whatever rubyesque things I want in there!
>
> Erik
>
> On Tue, Oct 27, 2009 at 9:44 AM, Martin Emde <[email protected]> wrote:
>> Erik,
>> I've had to generate a lot of my own routes rather than using resources.
>> Here's an example of what I'm doing to keep them clean:
>>   map.with_options :controller => "beers" do |beers|
>>     beers.beers   "beers.:format",     :action => "index",  :conditions =>
>> {:method => :get}
>>     beers.connect "beers.:format",     :action => "create", :conditions =>
>> {:method => :post}
>>     beers.connect "beers/new.:format", :action => "new",    :conditions =>
>> {:method => :get}
>>     beers.with_options :id => /\d+/ do |beer|
>>       beer.beer    "beers/:id.:format", :action => "show",    :conditions =>
>> {:method => :get}
>>       beer.connect "beers/:id.:format", :action => "update",  :conditions =>
>> {:method => :put}
>>       beer.connect "beers/:id.:format", :action => "destroy", :conditions =>
>> {:method => :delete}
>>     end
>>   end
>>   map.with_options :path_prefix => "beers/:beer_id", :name_prefix =>
>> "beer_", :beer_id => /\d+/ do |beer
>> |
>>     beer.resource  :bookmark, :only => [:show, :create, :update, :destroy]
>>     # etc...
>>   end
>> I had to separate the paths for integer ids and permalink ids and this is
>> what I came up with for the rather complex integer id part. It's not so bad
>> when deconstructed like that.
>> Hope that helps,
>> Martin Emde
>> Tw: @martinemde
>>
>>
>> On Tue, Oct 27, 2009 at 2:50 AM, Erik Pukinskis <[email protected]>
>> wrote:
>>>
>>> Hi Nick and Chris,
>>>
>>> Thanks for the tips!  As Nick says, it's more than just the single
>>> route, which is why what (Chris) you're suggesting doesn't quite get
>>> me there.
>>>
>>> I did come across the "default routing" plugin
>>> (http://github.com/caring/default_routing) which purports to attach
>>> resources to /, but it didn't work for me.  It put extra slashes in
>>> the routes.
>>>
>>> I patched it to generate proper URLs, but it still didn't seem to work
>>> quite right, and was requiring more and more patches.
>>>
>>> So, I'm just making all the routes by hand.  It's starting to get
>>> ugly, but we'll see how it ends up.  One issue is that the named
>>> routes are a mess.  I'm starting to give up named routes.  The benefit
>>> I get from the automagicness seems to be outweighed by the massive
>>> hackery I have to go through when the magic is wrong.
>>>
>>> Best,
>>> Erik
>>>
>>>
>>>
>>>
>>> On Sun, Oct 25, 2009 at 9:06 PM, Nick Zadrozny <[email protected]> wrote:
>>> > And I may have clicked send too soon, because that doesn't really answer
>>> > the
>>> > core of your question.
>>> > To be honest, if you really want to be explicit and map each of the
>>> > actions,
>>> > I say go ahead and do it manually. I'm going to assume that, since this
>>> > is
>>> > in the root of the URL path, this is the only controller that will be
>>> > handled in this way. In which case, no big deal expanding that out.
>>> > map.user ":id", :controller => "users", :action => "show", :conditions
>>> > => {
>>> > :method => :get }
>>> > map.user ":id", :controller => "users", :action => "update", :conditions
>>> > =>
>>> > { :method => :put }
>>> > map.user ":id", :controller => "users", :action => "destroy",
>>> > :conditions =>
>>> > { :method => :delete }
>>> > map.user ":id/edit", :controller => "users", :action => "edit",
>>> > :conditions
>>> > => { :method => :get }
>>> > Now, I left off the index, create and new actions here. They're the ones
>>> > that give me pause. Do you really want to put each action in the root of
>>> > your URL namespace? If so, cool, go for it. However, what I suspect
>>> > might
>>> > work equally well is to simply override the "show" case.
>>> > map.resources :users
>>> > map.user ":id", :controller => "users", :action => "show"
>>> > I think (but have not recently tested, so do some experimenting) that
>>> > this
>>> > should override the user_path helper method and generally redirect you
>>> > to
>>> > "/whomever" where appropriate, while still using the "/users" prefix for
>>> > other actions. At any rate, I seem to recall having done something
>>> > similar
>>> > with an older project of mine, so it may serve as an idea worth pursuing
>>> > for
>>> > your app.
>>> > I hope that's a bit more helpful!
>>> > --
>>> > Nick Zadrozny
>>> >
>>> > >
>>> >
>>>
>>>
>>
>>
>> >
>>
>
> >
>



-- 
Rob Kaufman
http://notch8.com
gtalk/jabber/email: [email protected]
p: 858-412-7749
f: 866-477-1620

--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---

Reply via email to