Questions tagged [nested-resources]

In REST, nested resource is a web resource composing another. Its reference is built over the reference of another web resource.

Definition

In REST-style architecture , a resource is simply a source of information, the one you want to expose. The resource is referenced by a global identifier such as an URI. When you deal with information structure such as composition, you’ll use nested resources. The reference of the embedded resource is then built over the reference of the composite resource.

For instance, a blog post http://example.com/posts/1 owns several comments http://example.com/posts/1/comments.

374 questions
1
vote
1 answer

CanCan deeply nested resources

I have a routes.rb that looks like this: resources :restaurants, :shallow => true do resources :orders do resources :foods end resources :categories do resources :foods end end something like this in my ability.rb works, if…
patrickdet
  • 91
  • 2
  • 10
1
vote
1 answer

Rails routes generate Post request for New action in nested resources

I have the following nested resources: resources :listings do resources :offers do member do put "accept" put "reject" end end end In my listings/show.html.haml, I have = button_to "Make Offer",…
AdamNYC
  • 19,887
  • 29
  • 98
  • 154
1
vote
0 answers

Rails 3 nested resources, polymorphic associations and forms

The question at hand deals with the key topics: Nested Resources Polymorphic Associations Forms We will assume we have Photos and Articles, both of which have Comments. This creates our Polymorphic Association. #Photo Model -> photo.rb class…
1
vote
3 answers

Rails 3.1 nested resource with composite primary key (id + parent_id)

Let's assume I need two resources nested in the routes.rb as follows: resources :post do resources :comment end By convention comments.id will be the comments primary key and comments.post_id will be a foreign key. I need the primary key to be…
1
vote
2 answers

Nested resource in Rails3, no route match

I have a nested route in rails 3 mapped as resources :maps do resource :versions member do post 'share' get 'share' end end but when i try to connect to http://localhost:3000/maps/35/versions/2 i obtains No…
Petecocoon
  • 23
  • 1
  • 4
1
vote
1 answer

Rails nested resources available in another context

I plan on having galleries with nested images, so images belong in a gallery. I would then like images to have a Boolean option to determine whether or not a particular image shows up on the front page. Setting up a nested resource with a Boolean…
YuKagi
  • 2,451
  • 3
  • 21
  • 26
1
vote
1 answer

How to reuse the nested Resource methods in the encompassing Resource methods?

I have a resource called Profile which nests a list of Port resources like so: { "profile": "abcd" "ports": [ { "port": "5687" "state": "state" "protocol": "protocol" …
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127
1
vote
1 answer

How to build an Active Recond query for the show action in the controller of the nested resource?

I have two models: Books and Chapters, where book has many chapters. I've set up the route like: match 'book/:book_title/:chapter/:chapter_title' => 'chapter#show', :as => "chapter" and the delegation to the Chapters controller, action show works…
lyuba
  • 6,250
  • 7
  • 27
  • 37
1
vote
2 answers

Rendering nested form partials in other controllers

I have three resources: Jobs, Questions and Answers. The relationships are: Job has many questions; Question has many Answers; Job has many Answers. I have nested all of the forms on the jobs/new view. Now the goal of the app is for the admins (us)…
1
vote
1 answer

ActiveRecord building for nested resource

(NOTE: Source code here https://github.com/cthielen/dss-evote) I've got a simple voting application. A survey is the set of questions to vote on, a ballot is a per-user instance of their preferences, and the ballot has_many preferences, which again,…
Christopher
  • 1,635
  • 5
  • 19
  • 30
1
vote
2 answers

rails : routes in nested resources

I use nested resources #route.rb resources :users do resources :posts end and with #route.rb match '/:username' => 'users#show', :as => :user I change /user/id to /username but, how change /users/username/posts to username/posts ?
JuanPablo
  • 23,792
  • 39
  • 118
  • 164
1
vote
1 answer

Nesting Resources 3 Levels Deep

I have an idea of what is going wrong, but am having trouble fixing it. To explain my situation again, I have 3 elements : Jobs, Questions and Answers . All of the relationships are set up below. Expanding on my previous question which had to do…
Igrabes
  • 244
  • 4
  • 15
1
vote
1 answer

Nested routes vs storing current ids in a session?

Picking up Rails 3 for my next web app. Basically I have a set of nested resources. Users => Apps => Form I spent some time earlier using sessions to hold an app_id so I could access that apps forms. But I then discovered nested routes in Rails…
Msencenb
  • 5,675
  • 11
  • 52
  • 84
1
vote
0 answers

Expected default behavior for Grails RESTful mapping to Nested Resources

I have my Grails Domain classes annotated with @Resource with the uri specifications in UrlMappings where I declare the resource nesting. But even though according to https://docs.grails.org/latest/guide/theWebLayer.html#restfulMappings it seems…
paulito415
  • 194
  • 1
  • 9
1
vote
2 answers

Rails nested rources and routes and how to set them up in route.rb

I think I have a handle on nested routes (great url helpers, and access and much more) and nested resources in forms with accepts_nested_attributes_for but what do I use in routes as I see both: resources :schools do resources :documents end and…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497