Re: [ruby-81] RESTful services that always work

From: stevenwulf
Sent on: Thursday, January 31, 2008 7:32 AM

Hi Loqi,

Another option might be to make a generator to automate the creation of 
your routes.  I've been avoiding map.resource because of the 
plural/singular problem so I make my own routes:

  map.with_options(:controller => 'systems') do |s|
    s.systems         'systems',             :action => 'index'
    s.show_system     'systems/:id/show',    :action => 'show'
    s.new_system      'systems/new',         :action => 'new'
    s.create_system   'systems/create',      :action => 'create'
    s.edit_system     'systems/:id/edit',    :action => 'edit'
    s.update_system   'systems/:id/update',  :action => 'update'
    s.destroy_system  'systems/:id/destroy', :action => 'destroy'
  end

This is a bit more tedious than map.resource, but if you create a route 
generator then it could make those routes for you.  There is a great 
railscast on using the generator framework within rails.

http://railscasts...

In general, railscasts.com has a lot of really helpful stuff.


Regards,
-Steven


Loqi wrote:
> I'm beginning to get more comfortable with the idea of making a plugin 
> for pluralization-independent Restful services. I'm just too green 
> with Rails to do it alone. I don't know how.
>
> I'm pretty sure everything the scaffold generator is producing is 
> sound. I have some inkling that the entire problem lies with the 
> map.resources method. But I can't quite find the exact failure. The 
> routes it produces seem to be named in a silly way, but I can't see 
> why those silly names don't work. Here's as far as I got:
>
>
> Routes generated by map.resources for an uncountable-noun-named model:
> fish_index     GET  /fish             {:controller=>"fish", 
> :action=>"index"}
> new_fish       GET  /fish/new         {:controller=>"fish", 
> :action=>"new"}
> edit_fish      GET  /fish/:id/edit    {:controller=>"fish", 
> :action=>"edit"}
> fish           GET  /fish/:id         {:controller=>"fish", 
> :action=>"show"}
> . . .
> (This set crashes when you try to use the routes.)
>
>
> Pluralizing-noun-named models get this:
> carps          GET  /carps            {:controller=>"carps", 
> :action=>"index"}
> new_carp       GET  /carps/new        {:controller=>"carps", 
> :action=>"new"}
> edit_carp      GET  /carps/:id/edit   {:controller=>"carps", 
> :action=>"edit"}
> carp           GET  /carps/:id        {:controller=>"carps", 
> :action=>"show"}
> . . .
> (This set is the regular Rails "convention over configuration" routes 
> that don't crash.)
>
>
> My fantasy is to generate RESTful conventions that are consistent, 
> non-subtle, and work every time, no matter what:
> fish_index     GET  /fish/index       {:controller=>"fish", 
> :action=>"index"}
> fish_new       GET  /fish/new         {:controller=>"fish", 
> :action=>"new"}
> fish_edit      GET  /fish/edit/:id    {:controller=>"fish", 
> :action=>"edit"}
> fish_show      GET  /fish/show/:id    {:controller=>"fish", 
> :action=>"show"}
> . . .
> (This set doesn't exist, but probably should.)
>
>
> But I don't think the weird route names are actually the problem. I 
> don't yet know enough about Rails to find where it's falling on its 
> face. I tried the solution described here...
> http://somethingl... 
>
> ...where it says to provide an explicit or contrived singular noun to 
> the resources method call in routes.rb, like this:
> map.resources :fish, :singular => :fish_instance
> This would be a stopgap measure until I can do something more 
> satisfying, but I couldn't actually get it to work, and I'm not sure 
> why. I'll keep prodding at my personal problem until I find some good 
> workaround.
>
> Anyway, I'd like to fashion some kind of general plugin solution that 
> would help anyone (especially me) who wants to use RESTful Rails with 
> a declawed inflictor. It doesn't seem too difficult if you know how to 
> do it. But I guess nothing is difficult if you know how to do it.
>
> If some kind soul out there is willing to help this thing happen, I'd 
> be most grateful for some mentoring guidance while I puzzle it 
> through. Or maybe the other way around; If this is easy for an 
> experienced person to just do, I'd like to watch and learn. Please 
> contact me or this listserve if you can offer some help to a fellow 
> traveler in distress.
>
> Loqi
>
> And hey, thanks for the tip on The Rails Way, Rich. I'll look for that 
> one.
>
>
>
> -- 
> Please Note: If you hit "REPLY", your message will be sent to everyone 
> on this mailing list ([address removed])
> This message was sent by Loqi ([address removed]) from The East Bay Ruby 
> Meetup Group.
> To learn more about Loqi, visit his/her member profile: 
> http://ruby.meetu...
> To unsubscribe or to update your mailing list settings, click here: 
> http://www.meetup...
>
> Meetup.com Customer Service: [address removed]
> 632 Broadway New York NY 10012 USA
>

Amazon Web Services

AWS credits at each meeting

Apress

eBook discount coupons at every meeting.

jetBrains / RubyMine

RubyMine licenses at each meeting

Balsamiq Mockups

3 free Balsamiq licenses per year

People in this
Meetup are also in:

Log in

Not registered with us yet?

Sign up

Meetup members, Log in

or
By clicking the "Sign up using Facebook" or "Sign up" buttons above, you agree to Meetup's Terms of Service