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
7
votes
2 answers

form for nested resource

I have gone through tons of the form_for nested resource questions and can't get any of the solutions to work for me. I figured its time to ask a personalized question. I have two models, jobs and questions, jobs has_many questions and questions…
Igrabes
  • 244
  • 4
  • 15
7
votes
1 answer

Rails 3 routing: Avoiding Deep Nesting

Today I realised I'd gotten a little carried away with nested resources: resources :organisations do resources :studies do resources :settings end end The Rails guidelines (and my own thoughts) suggest that you shouldn't nest more than 1…
Ant
  • 3,877
  • 1
  • 15
  • 14
7
votes
3 answers

Does anybody have any tips for managing polymorphic nested resources in Rails 3?

In config/routes.rb: resources :posts do resources :comments end resources :pictures do resources :comments end I would like to allow for more things to be commented on as well. I'm currently using mongoid (mongomapper isn't as compatible…
Ryan
  • 2,102
  • 4
  • 18
  • 23
6
votes
1 answer

Rails 3 Nested resource routes inherits parent constraints, how to avoid it?

It you define constraint on "id" in parent resource: resources :foo, constraints: { :id => /CONST/ } do resources :bar end The nested resource will inherits that constraint for its own id, thus the generated routes will be…
5
votes
1 answer

Testing nested resources with RSpec

I am trying to create tests for nested resources in Rails. The relevant route definition is: resources :communities do resources :contents, :type => 'Content' end Using RSpec and factory_girl, I am trying to get started with testing with…
5
votes
3 answers

Yii2 - nested resources best practice

Using Yii2 framework I cannot find any built-in functionality to implement something called nested resources in Ruby on Rails (http://guides.rubyonrails.org/routing.html#nested-resources) For example, an Article has many Comments. So I want that…
Andrey Pesoshin
  • 1,136
  • 1
  • 14
  • 30
5
votes
2 answers

Rspec and Rails with View Tests and Nested Resources

I'm working on a Yahoo Answers sort of app to improve my Rails skills. So far I've set two models "Question" and "Answers" and they are nested this way: resources :questions do resources :answers end I've made tests for the controllers,…
4
votes
3 answers

Rails 3 - Best way to handle nested resource queries in your controllers?

If there's one thing I've learned about Rails 3 is if I'm having a hard time doing something, I'm probably doing it wrong. So I'm looking for help. I have a few models which are related in a many to many relationship. I am able to create the…
4
votes
0 answers

rails mountable engine - SQLite3::SQLException: no such table

I am following the Rails Guide Getting Started with Engines. The only thing that is different is that I am using the RubyMine IDE. I am using ruby 2.5.0 and rails 5.1.5. Everything has gone smoothly until I reached section 4, "hooking into an…
Randall Blake
  • 684
  • 2
  • 6
  • 15
4
votes
2 answers

What's the "right" way to create a many-to-many relationship in a Restful API

I try to find the best practice in order to create a Many-to-Many relationship in a Restful API. The usecase is really simple, but i cannot really found the "right" way to do it. In our model, we have Kid that are related with a Many-to-Many…
4
votes
1 answer

Rails nested form with nested resource: update belongs_to association when creating new has_many

I have been beating my head against a wall with a particular use case for nested forms (I'm using Rails 2.3.5). Essentially I have Project and Payment models that looks like this class Project < ActiveRecord::Base has_many :payments end class…
Lou Kosak
  • 289
  • 6
  • 10
4
votes
0 answers

Improperly configured nested resource using HyperlinkedModelSerializer

I have chosen the Django REST Framework and drf-nested-routers to build an API for Products and ProductReports. Here are the relevant classes: # models.py from django.db import models class Product(models.Model): created_at =…
JJD
  • 50,076
  • 60
  • 203
  • 339
4
votes
1 answer

I can't create model objects using accepts_nested_attributes_for. It won't create the nested object

My model structure looks like this: Board has_many Topics. Topic has_many Posts. app/models/board.rb class Board < ActiveRecord::Base has_many :topics end app/models/topic.rb class Topic < ActiveRecord::Base belongs_to :user belongs_to…
4
votes
3 answers

DRYing up Rails Views with Nested Resources

What is your solution to the problem if you have a model that is both not-nested and nested, such as products: a "Product" can belong_to say an "Event", and a Product can also just be independent. This means I can have routes like…
Lance
  • 75,200
  • 93
  • 289
  • 503
4
votes
2 answers

RSpec routing test problems with params in nested resources

i have a strange problem.. rspec generated a class named menus_routing_spec.rb in spec/routing the tests are failing because menus is a nested resource of restaurant. this is my test: describe MenusController do before :each do …
damir
  • 1,928
  • 1
  • 16
  • 26
1
2
3
24 25