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
4
votes
0 answers

Breaking shallow nested resources (non-shallow resources)

I have problem with shallow nested resources. I my routes there is a big tree of nested resources but one of them have to be non-shallow. Simply example: resources :days, shallow: true do resources :meals, shallow: true do resources…
pablo
  • 384
  • 2
  • 5
  • 17
4
votes
2 answers

Sharing Application Resources in WPF

From this page, I read: If your application uses custom controls and defines resources in a ResourceDictionary (or XAML Resources node), it is recommended that you either define the resources at the Application or Window object level, or define…
Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
4
votes
1 answer

Active Admin before_validation hook?

I have an Active Admin model, :gallery, and it has a nested paperclip resource, :images. :gallery has_many :images. :gallery has a field, :title, which is required. When I submit without a title, the other fields persist (:description, :location)…
Mild Fuzz
  • 29,463
  • 31
  • 100
  • 148
4
votes
1 answer

nested routes and form_for and models using has_one and belongs_to

How to map out has_one model with nested routes and how to add a form_for for /localhost:3000/users/1/profile/new,html.erb following RESTful database? User has one Profile. Models class Profile < ActiveRecord::Base attr_accessible :name, :surname …
3
votes
1 answer

DRY in ROR routes description

I have nested combination of routes in json rest application used for different dropdown lists and grouping resources :cities, :only =>[:index,:show] resources :regions, :only =>[:index,:show] do resources :cities, :only=>[:index, :show] …
Fivell
  • 11,829
  • 3
  • 61
  • 99
3
votes
1 answer

Testing Nested Resources Controller with RSpec - count doesn't change by 1

I have nested resources: resources :portfolios do resources :asset_actions end And following RSpec Controller: asset_actions_controller_spec.rb before(:each) do @portfolio = Factory(:portfolio) end describe "POST create" do describe "with…
dpaluy
  • 3,537
  • 1
  • 28
  • 42
3
votes
1 answer

Cancan not loading nested resources as I expect it to

Cancan is working fine when user's are logged in. But when a user is a "guest" I would like them to be able to see some photos, but not those where the Photo's parent Post has a restriction employees_only flag set. Problem is if there is any photo…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
3
votes
1 answer

Link_to Routing Issue With Nested Resources

I have two models Jobs and Questions. A job has many questions and questions belong to a job. I've set up the resources in the model, as well as the routes. I am having an issue trying to link_to the Show method of the questions controller on the…
Igrabes
  • 244
  • 4
  • 15
3
votes
1 answer

Rails - Nested Objects Deletion

I want to delete the nested object book, that is owned by a user. In the user#show page appears all the books related to that user. Besides each book there is a link to delete it. Here is my code: routes.rb: resources :users do resources :books,…
3
votes
1 answer

how to modify form_with when using nested resources in rails

I am learning to use nested resources in rails. To keep it simple and reproducible I have setup a very simple blog app with two resources posts and comments. Most of the code has been generated by scaffold. I have successfully modified post#show to…
Imran Ali
  • 2,223
  • 2
  • 28
  • 41
3
votes
1 answer

Rails RESTful delete in nested resources

Okay, so here's an example scenario. There is a student resource resources :students, and students has and belongs to many collections: resources :clubs, resources :majors, etc. So we can set up our routes easily enough... resources :clubs do …
3
votes
1 answer

How to save a nested resource in ActiveRecord using a single form (Ruby on Rails 5)

I have two entities with a many-to-one relationship. User has many Addresses. When creating a User I want the form to also create a single Address. The entities are nested. Approach 1: The code below works, but only saves the User, no associated…
3
votes
1 answer

Do nested resources need to be paged too?

I'm building a REST api. A simple example of a problem I'm looking to solve involves 2 domain entities: posts & comments. Currently a GET request to http://myapidomain.com/posts returns a collection of posts, where each post contains a link to…
apostrophedottilde
  • 867
  • 13
  • 36
3
votes
2 answers

Rails - nesting resource with two parents

Say I have a child model with two parent models: Event has_many tickets Person has_many tickets Ticket belongs_to Event Ticket belongs_to Person Routes are mapped so Ticket always nests within Event or Person: resource :people do resources…
Ed Haywood
  • 219
  • 1
  • 3
3
votes
3 answers

In Rails, how can I share a private method to nested controllers?

I have a resource of Player that has various nested resources, such as: Measurable and Workout. I have a variable that is used int he Player's header on their pages and it has a variable I need to be set whether I'm accessing an action from the…
daveomcd
  • 6,367
  • 14
  • 83
  • 137
1 2
3
24 25