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

Using a different foreign key with nested resources in Rails

When working with nested resources in Rails is it possible to use a value/field other than the primary key of the parent resource as the foreign key for the child resource objects? e.g. if I have "books" that belong to "authors", I pass the…
user3092118
  • 351
  • 1
  • 3
  • 10
1
vote
2 answers

Nested Resource Creation in Parent Form

I have a class called Quote which has_many :line_items, as: :line_itemable (line_items are polymorphic). A quote must have at least one line_item upon creation, so in my Quote creation form I have a section dedicated to adding line items. My routes…
davidicus
  • 630
  • 1
  • 6
  • 16
1
vote
2 answers

How to RESTfully support the creation of a resource which is a collection of other resources and avoiding HTTP timeouts due to DB creation?

In my application I have the concept of a Draw, and that Draw has to always be contained within an Order. A Draw has a set of attributes: background_color, font_size, ... Quoting the famous REST thesis: Any information that can be named can be a…
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
1
vote
2 answers

Rails 4 select_tag with nested resource

I have a resource that looks like this: resources :teams do [...] get 'tags/:tag', to: "teams#show", as: :tag end Each Team can have multiple Posts which in it's turn can have multiple Tags. In my teams show view I want to display a select_tag…
Anders
  • 2,903
  • 7
  • 58
  • 114
1
vote
3 answers

Deeply Nested resources Form

I'm struggling to get this working, I've read a lot but couldn't find whats the problem here. routes.rb resources :scripts do resources :reviews resources :issues do resources :comments end end comments_migration create_table…
Mini John
  • 7,855
  • 9
  • 59
  • 108
1
vote
2 answers

How to retrieve user 2nd level resource with nested resources

I have a user model that has many photos and those photos have many tags. My routes: resources :users do resources :photos do resources :tags end end My view: <%= @user.photos.tags.count %> I don't know how to retrieve all the tags a…
Gibson
  • 2,055
  • 2
  • 23
  • 48
1
vote
1 answer

ActiveAdmin Nested Resource Index View

I've got MenuItem's nested under Menu using a belongs_to This works great if i do not declare the index block (active admin works it out automagically) but if i declare my own block it shows all the MenuItems for all the menus. How can I tell my…
Will
  • 4,498
  • 2
  • 38
  • 65
1
vote
1 answer

Strong parameters with a has_many array not allowing hash keys

My two models: Object embeds_one 'sub_object' SubObject embeds_many 'sub_sub_objects' This is my params hash: {"object"=> {"sub_object_attributes"=> {"sub_sub_objects_attributes"=> …
user1032752
  • 751
  • 1
  • 11
  • 28
1
vote
1 answer

Nested resources linking

I have a category with a subcategory and the subcategory has posts. I'd like to link it as following: /categoryname/subcategoryname/post_id/postname I've tried doing so by putting this in my routes: resources :categories do resources…
CaptainCarl
  • 3,411
  • 6
  • 38
  • 71
1
vote
1 answer

Displaying error messages of a nested resource on its parent's resource views

I have a nested resource (child) that is only viewed and edited on its parent's resource views. How to make error messages of the child display on its parent's views when an action of the child is called and the child is invalid? In order to do this…
Arta
  • 5,127
  • 5
  • 25
  • 23
1
vote
2 answers

Proper routing for User model dashboard and his posts in Rails 4.0

My question here is about the proper way to do the routing and controllers for my simple app. Honestly I got stuck with the User model and Post model. I've got it routed like this: match '/dashboard', to: 'dashboard#user' In the controller it…
Anton
  • 137
  • 8
1
vote
4 answers

link_to syntax in Rails 4 for nested resources

I really don't understand how to link to another view in rails. I load datas in /products/index.html.erb and want to retrieve product id form one product to point to another view : subjects/index.html.erb what is the correct syntax to have this url…
1
vote
2 answers

Different view pages

I want in application>layout to have something like " link_to kosh,.... " so a simple user can view all the posts that only kosh has posted. What changes i have to make,is that possible ?? senario: i am a simple user and when i go to the web i see a…
marios
  • 261
  • 8
  • 26
1
vote
1 answer

Rails - Sorting deep nested resources on index page from dropdown by primary model

So I have three models: Topic, Post and Paragraph. Each Topic has many Posts and each Post has many Paragraphs. What I need to achieve is to sort the Paragraphs by Topic on paragraphs/index.html.erb. I of course have the dropdown menu including all…
1
vote
1 answer

How to Link PGSeaerch results to Index Page in Nested Resources?

I finally figured out how to implement pg_search's multisearch feature. But I'm having trouble making a usable search page that displays links back to the appropriate nested pages. How can I pass the proper id so I could link to the nested views.…
Serge Pedroza
  • 2,160
  • 3
  • 28
  • 41