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
2
votes
1 answer

Rails 3 routes with slashes and nested resources

I'm having trouble adding a slashed slug and nested routes. If I have these routes: resources :courses do resources :registrations end I have these URLs: /courses/7 /courses/7/registrations If I change to_param in Course.rb, I can get some slugs…
BenB
  • 10,300
  • 7
  • 32
  • 30
2
votes
1 answer

Nested resource view spec seems to be referring to a non-existent route

Rails 3.1.0 Rspec 2 In a view spec for a nested resource, do I need to instantiate/stub the parent resource before I stub the nested resource? I am asking this because all my view specs are failing for a new nested resource I have introduced in…
2
votes
2 answers

Routing error calling "new" method with nested resource

I have two nested resources: class Customer < ActiveRecord::Base has_many :locations, :dependent => :destroy accepts_nested_attributes_for :locations end class Location < ActiveRecord::Base belongs_to :customer end In routes.rb I…
kranz
  • 599
  • 1
  • 6
  • 23
2
votes
2 answers

Improperly routed Rails Destroy method on nested resource

I have a List object, with nested Tasks. I have created a page that displays individual tasks, and also a page that allows a user to edit individual tasks. I now want to add the ability to delete a task from a list on the tasks edit page. Using the…
Mike Caputo
  • 1,156
  • 17
  • 33
2
votes
1 answer

Ruby on Rails form_for causing path error

In my Ruby on Rails code, I have the following edit.html.erb file for tasks: <%= render 'form' %> I then have a _form template in the same directory with the following code: <%= form_for @task do |f| %> <%= fl.label :title %>
<% end…
Mike Caputo
  • 1,156
  • 17
  • 33
2
votes
2 answers

form_for with nested resource doesn't submit a post-request

first: I promise I've read through every post regarding this topic, searched the whole web, but still don't know... I have to models Trip (has_many) and Accomodation (belongs_to). Accomodations are nested in a Trip: resources :trips do resources…
2
votes
2 answers

Rails 3.1 has_one nested resource: routing not generating "all" paths

I have a has_one relation: # supplier.rb has_one :presentation ... # presentation.rb belongs_to :supplier ... and the folowing nested routes for them: # routes.rb resources :suppliers do resource :presentation end running rake…
2
votes
2 answers

Combining shallow and non-shallow routes on a single Rails resource

Let's say I have a Magazine model and Ad model, such that Magazine :has_many => :ads. I have setup my nested resource routing as follows: resources :magazines do resources :ads, :shallow => true do get 'search', :action => :search, :on =>…
Dave W.
  • 1,576
  • 2
  • 18
  • 29
2
votes
2 answers

Ruby / Rails - AJAX pagination of nested resources - How do I determine the parent resource?

My model has Posts, Users, and Comments. Users can leave Comments on/about Posts. Every Comment belongs to a User and a Post. Therefore, the Comment model has a user_id field and a post_id field. When viewing a Post, I want to paginate through that…
2
votes
1 answer

Laravel: How can I write a policy class for API methods on a nested resource controller?

I have a many to many relationship that I'm working with between User and Task models. A user belongs to many tasks and a task belongs to many users. I have a pivot table called task_user. In my API, I have a route defined as…
Timothy Fisher
  • 1,001
  • 10
  • 27
2
votes
1 answer

Nested resources segments misplacement

I'm trying to implement basic social network features to allow users to add, delete friends, accept and decline friedship requests. my user resource looks like this: resources :users resources :friends, :controller => :relations end which…
bassneck
  • 4,053
  • 4
  • 24
  • 32
2
votes
1 answer

Rails 3 nested resources with users (Devise) structure

I'm having general structural issues with Rails 3 and the new routes.rb is getting me a bit confused. Thanks for any help or guidance. I have a forum application with nested resources. There are sections, topics, and replies. The routes.rb structure…
a3uge
  • 417
  • 4
  • 14
2
votes
1 answer

Rails 3 - Nested Resources Routing - One to One relationship

Having some trouble with some nested resources routing. What I'm trying to do is link to a user's profile page for editing purposes. In my view it is written as: <%= link_to "Edit Profile", edit_user_profile_path(current_user) %> Which errors out…
Kombo
  • 2,371
  • 3
  • 34
  • 64
2
votes
1 answer

Multiple rails 5 nested routes from one controller

I have nested routes of categories/subcategories/products and my controller and view files are setup accordingly, but I now have some products that don't have subcategories. How, if possible, can I have some products part of a category, while…
Charles Smith
  • 3,201
  • 4
  • 36
  • 80
2
votes
1 answer

How to get the form_for working for a nested resource - with a slight twist

I'm looking to have the child model added/edited on it's own form, not within the parent form. any example I have seen has the child added on the same form as the parent. Since I'm adding the twist of adding/editing on a separate form, I'm wondering…
daz13
  • 245
  • 2
  • 15