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

Issue with named routes for nested resources

I have a rails 3 nested resource defined as follows resources :candidates do collection do get :bookmarked end resources :bookmarks, :only => [:create, :destroy] end The bookmarked action in the candidats collection will create a new…
ppaul74
  • 751
  • 1
  • 13
  • 21
0
votes
1 answer

How to set up partially nested resourceful routes?

On my Rails site, users post Listings of items they want to sell. Other users can browse these listings and click a link to contact the seller, which should create a MessageThread: # MessageThread properties... listing_id poster_id # (listing_id's…
Nick B
  • 1,101
  • 9
  • 19
0
votes
1 answer

Rails form_for with nested resources: "No route matches"

I have the following nested resources in my routes.rb file. The inner resource specifies a controller name. resources :batches, :except => [:new], :path => "sets" do resources :tags, :controller => "batches_tags" end In the view for…
Matt Rubin
  • 315
  • 2
  • 8
0
votes
1 answer

Rails 3 SQL query inside nested resources

Say I have a series of nested resources (Magazine, Edition, and Ad) in a Rails application, such that magazines have many editions, which subsequently have many ads. How can I do a query to produce all ads in all editions of a given magazine, and…
Ryan Atallah
  • 2,977
  • 26
  • 34
0
votes
2 answers

How to write nested axios post request in rails project?

I have been trying to convert the views of a project written initially in Ruby on Rails and I have pretty much succeeded in it. The next step is to write React APIs that will request and send data to the rails models. Here is where I am stuck. So…
Aitzaz
  • 43
  • 7
0
votes
1 answer

RESTful form_for with nested resources via join table

I'm trying to build an app where there is a model for "Jobs" that can be associated with a "Tags" model where the associations are tracked using a join table. I'm wanting to find it it's possible to use a resource based form_for add checkboxes in…
Reuben
  • 53
  • 5
0
votes
1 answer

In Rails / Active Admin, how do I get the nested resource in the index title?

I'm using active admin and I'd like to get the nested resource in the index title for optional nested resource, for example for the route: For example I will have two models set up like this: ActiveAdmin.register Document…
CafeHey
  • 5,699
  • 19
  • 82
  • 145
0
votes
1 answer

Form helper, nested resources without setting the parent resource

If we've models as: class Book < ApplicationRecord has_many :chapters end class Chapter < ApplicationRecord belongs_to :book end with routes: resources :books do resources :chapters end and we want to create a form as: <%= form_with(url:…
Sumak
  • 927
  • 7
  • 21
0
votes
1 answer

Probleme on nested ressources rails

I am coding a Rails app, where I would like to show specific restaurants, hotels and bars for a specific city. My problem is when I want to show a specific instance of a Restaurant (for now), I always end-up on the page of the Restaurant with the id…
0
votes
1 answer

Exposing a Specific Action of a Nested Route

Using this as an example contexted: Post has_many comments Comment belongs_to post I have a route that looks like: resources :posts do resources :comments end How do i create a route that exposes comments#index? An example use case would be... I…
Mario Zigliotto
  • 8,315
  • 7
  • 52
  • 71
0
votes
1 answer

Rails form_for loop with nested resources

I have three resources: Jobs, Questions and Answers. The relationships are: Job has many questions; Question has many Answers. I have created a nested form on the Jobs form view, which includes the creation of jobs and questions. Those are both…
Igrabes
  • 244
  • 4
  • 15
0
votes
2 answers

Rails 3 Nested Resources Edit/Update method - routing error

I need some help with nested resource actions. I have three nested resources: Jobs, Questions and Answers. I am currently only trying to get the edit/update method to work for the questions controller. The relationship is as so: Jobs has_many…
0
votes
1 answer

Rails 6: Dynamic nested forms: get id of nested resource selected by fields_for and collection_select

If you're facing a similar issue you might found interesting (re)reading this posts: Can someone explain collection_select to me in clear, simple terms? I'm trying to implement nested forms with several models and a dynamically added…
Sumak
  • 927
  • 7
  • 21
0
votes
1 answer

Rails :include doesn't include

My models: class Contact < ActiveRecord::Base has_many :addresses has_many :emails has_many :websites accepts_nested_attributes_for :addresses, :emails, :websites attr_accessible :prefix, :first_name, :middle_name, :last_name, :suffix, …
0
votes
1 answer

Rails 3 Routing Error with Nested Resources

In my Rails application, there are many games, and each game has it's own set of leaderboards. It makes sense then, to have the leaderboards nested in the game, so you can only get to a leaderboard through a game. I setup my routes.rb file as such…
Ethan Mick
  • 9,517
  • 14
  • 58
  • 74