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

How to link_to user's particular page - nested resources

I have the following code: <%= link_to new_book_path(controller: :books, action: 'new', id: comment) %> #also tried: <%= link_to new_book_path(comment.user.id) %> #outputs: undefined id <%= link_to new_book_path(comment.user_id) %> #leads to my…
superbot
  • 401
  • 3
  • 19
1
vote
3 answers

Rails nested resources

Here's the routes.rb: map.resources :assignments, :shallow => true do |assignment| assignment.resources :problems end How do i get the url to edit a problem (/assignments/xyz/problems/abc/edit), in code? I have tried both …
Akshay
  • 11,803
  • 5
  • 29
  • 26
1
vote
2 answers

Laravel 5.4 route simplification

I've been trying to find some documentation on how to accomplish the following, but it seems like maybe I'm not using the correct search terms. I would like to implement some simplified routes in Laravel 5.4 by omitting the route name from the path…
Eric Norcross
  • 4,177
  • 4
  • 28
  • 53
1
vote
1 answer

Rails nested resources (many levels) Class treated as Module

These are my models: class Company < ActiveRecord::Base has_many :products end class Product < ActiveRecord::Base belongs_to :company has_many :prices end class Price < ActiveRecord::Base belongs_to :product end I defined…
kaczor1984
  • 467
  • 2
  • 12
  • 22
1
vote
0 answers

How to access the edit method of a nested resource with simple_form in rails?

I have 3 models: Book, UserBook, and User (from devise). User and Book are linked though UserBook with a has_many:users through: :user_books. I've been trying to access the edit and destroy methods in user_books using a simple form in books#show to…
Bobby M
  • 11
  • 3
1
vote
1 answer

Generating the URL of a nested resource without its parent (without using shallow)

In our application, many resources are nested under a common resource representing an organization. Most URLs include an organization ID the following pattern: /:organization_id/notifications/:id. My problem is that I always have to give the current…
Vincent Robert
  • 35,564
  • 14
  • 82
  • 119
1
vote
1 answer

Rails 3 - session's and routing!

I am building a web app which has multiple projects. The general data model is such that each project has many resources such as documents, registers, etc.Something along the lines of: class Project < ActiveRecord::Base has_many :documents,…
1
vote
2 answers

API Upload files with metadata

I'm looking for some guidance here. Scenario: I have a Post model with a polymorphic relation to a Comment model. Whenever I want to create a new comment for a given post I have the following endpoint: $router->post('/posts/{post}/comments',…
1
vote
1 answer

Using nested controllers

Since my site had an admin section and a normal (front-end user) section, I needed to structure the articles controller in such a way that it was RESTful. So what I did was , have 2 articles controllers, 1 nested under the admin namespace (which…
Shreyas
  • 8,737
  • 7
  • 44
  • 56
1
vote
1 answer

Laravel nested resource security

On a project I'm currently working on, I have nested resources like this route()->resources('user', 'UserController'); route()->resources('user.place', 'PostController'); route()->resources('user.place.picture', 'PictureController'); Everything is…
dib258
  • 705
  • 8
  • 25
1
vote
1 answer

Pundit headless policy for nested resource

How can I authorize an action from a controller without a model based on another model object? Let's say I have a model called Server and I have a nested controller called config_files_controller which doesn't have a corresponding model. I want to…
Dan F.
  • 345
  • 1
  • 3
  • 12
1
vote
1 answer

Nested resource [Model] reference must exist error on form submit

I've looked at all kinds of threads on the same error and tried different things people suggested, but can't seem to figure this one out. I'm using Rails 5 and keep getting this error when I try to submit my form: Step reference must exist Here are…
1
vote
2 answers

Getting the parent resource from the URL

I've got two objects (@stacks and @stories) with has_many relationships (through @anthologies). Stories can be viewed individually (/stories/1/) or as a collection in a Stack (/stacks/1/stories/1/). map.resources :stories map.resources…
iamlemur
  • 151
  • 2
  • 8
1
vote
1 answer

Rails: Triple nested forms example

I have looked around for weeks trying to find an example of triple nested forms that include all the components, including how to handle form_for with the deeply nested model. Fairly new to Rails, but would love if someone could show post an example…
1
vote
1 answer

Devise current_user vs user_id passed in params, nested resources update action

I am using Devise for authentication. I have two models where a user has one profile and profile belong to user: class User < ActiveRecord::Base has_one :profile, dependent: :destroy end class Profile < ActiveRecord::Base belongs_to…
Elvyn Mejia
  • 307
  • 4
  • 18