Ran into a great problem. REST, as it's implimented via Rails, identifies
the URL as a plural in every case. So you would retrieve a single issue
through /issues/<insert key here>. This seems to be technically incorrect.

I find other (non-Rails) documentation talking about this being singular
for getting a single issue and plural for a list.

And this is also how the site I'm trying to access is configured. Which
means that every time I try to GET a single issue the ActiveResource is
calling for /issues/<insert key here> instead of the correct /issue/<insert
key here>.

Does anyone know of a way to workaround this problem using ActiveResource?


Maybe I should ask if anyone else agrees that this is a problem in the
implementation of the REST api in ActiveResource?

--
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@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Tom Allison at Aug 1, 2012 at 5:22 pm
    Well, I added an inflector to fix this one.
    And I had to strip the '.json' by adding this to the model:

    class << self
    def element_path(id, prefix_options = {}, query_options = nil)
    prefix_options, query_options = split_options(prefix_options) if query_options.nil?
    "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
    end

    def collection_path(prefix_options = {}, query_options = nil)
    prefix_options, query_options = split_options(prefix_options) if query_options.nil?
    "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
    end
    end

    but I have a lot of associated models to create for this API. Where do I put something like this to override ALL instances of the ActiveResource element_path and collection_path calls?

    On Jul 31, 2012, at 4:47 PM, Tom Allison wrote:

    Ran into a great problem. REST, as it's implimented via Rails, identifies the URL as a plural in every case. So you would retrieve a single issue through /issues/<insert key here>. This seems to be technically incorrect.

    I find other (non-Rails) documentation talking about this being singular for getting a single issue and plural for a list.

    And this is also how the site I'm trying to access is configured. Which means that every time I try to GET a single issue the ActiveResource is calling for /issues/<insert key here> instead of the correct /issue/<insert key here>.

    Does anyone know of a way to workaround this problem using ActiveResource?



    Maybe I should ask if anyone else agrees that this is a problem in the implementation of the REST api in ActiveResource?
    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Daemian mack at Aug 3, 2012 at 7:13 am
    Sounds like you want to look at collection_name on your class.

    More here...

    http://www.quarkruby.com/2008/3/11/consume-non-rails-style-rest-apis/


    On Tue, Jul 31, 2012 at 4:47 PM, Tom Allison wrote:

    Ran into a great problem. REST, as it's implimented via Rails, identifies
    the URL as a plural in every case. So you would retrieve a single issue
    through /issues/<insert key here>. This seems to be technically incorrect.

    I find other (non-Rails) documentation talking about this being singular
    for getting a single issue and plural for a list.

    And this is also how the site I'm trying to access is configured. Which
    means that every time I try to GET a single issue the ActiveResource is
    calling for /issues/<insert key here> instead of the correct /issue/<insert
    key here>.

    Does anyone know of a way to workaround this problem using ActiveResource?


    Maybe I should ask if anyone else agrees that this is a problem in the
    implementation of the REST api in ActiveResource?

    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    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@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • masta Blasta at Aug 3, 2012 at 9:09 pm

    Tom Allison wrote in post #1070825:
    Ran into a great problem. REST, as it's implimented via Rails,
    identifies
    the URL as a plural in every case. So you would retrieve a single issue
    through /issues/<insert key here>. This seems to be technically
    incorrect.

    I find other (non-Rails) documentation talking about this being singular
    for getting a single issue and plural for a list.

    And this is also how the site I'm trying to access is configured. Which
    means that every time I try to GET a single issue the ActiveResource is
    calling for /issues/<insert key here> instead of the correct
    /issue/<insert
    key here>.

    Does anyone know of a way to workaround this problem using
    ActiveResource?


    Maybe I should ask if anyone else agrees that this is a problem in the
    implementation of the REST api in ActiveResource?
    What you express is not a problem. You're confusing parameters and
    actual path segments.
    The url in rails is indicative of the controller and action at that
    point in the site. At its core rails routing looks something like
    map.connect ':controller/:action/:id.:format' actions assigned restful
    verbs will figure out on their own path, but custom actions will need
    their own path segment.

    something like mydomain.com/issues means route to the 'issues'
    controller with no paramaters, which most commonly will go to the index
    action.

    something like mydomain.com/issues/4 means route to the 'issues'
    controller with parameters {id: 4}. By default mydomain.com/issue/4
    would go to a different controller ('issue' which would cause naming
    conflicts). You can of course get around this by hardcoding resource
    paths.

    So from there you can figure out where
    /publishers/1/magazines/2/photos/3 goes. Publishers controller, get
    action, param id:1, magazines controller, get action,....

    This should tell you everything you need to know
    http://guides.rubyonrails.org/routing.html

    Whether or not inflections and pluralizations are a good thing to begin
    with, that's a whole nother thread.

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJul 31, '12 at 8:47p
activeAug 3, '12 at 9:09p
posts4
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase