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

How to nest collection routes?

I use the following routes configuration in a Rails 3 application. # config/routes.rb MyApp::Application.routes.draw do resources :products do get 'statistics', on: :collection, controller: "statistics", action: "index" end end The…
2
votes
2 answers

How do I setup the views for nested resources that are displayed as tabs within their parent resource in Rails?

I have a resource Company that has many Projects and People. The index action for the companies displays each company in a table. The show action shows some additional information about it, and then what I'd like to show is another table, with tabs…
Logan Serman
  • 29,447
  • 27
  • 102
  • 141
2
votes
1 answer

link_to create new nested_resource

I defined the next things: task.rb: class Task < ActiveRecord::Base belongs_to :worker attr_accessible :done, :name end worker.rb: class Worker < ActiveRecord::Base has_many :tasks attr_accessible :name end I wrote the next code in…
Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138
2
votes
1 answer

set current user when creating a comment with inherited_resource rails

I am using Rails Inherited_resource gem in my comments controller, and comments is a nested resource so: resources :projects do   resources :comments do end I also have a belongs_to in the comments controller: belongs_to :project, :finder…
user1883793
  • 4,011
  • 11
  • 36
  • 65
2
votes
2 answers

High level Rails patterns: organizing views around nested doc, chapter, page hierarchy

What's the Rails way of displaying the views for a somewhat deeply nested hierarchy? Seems like a simple question but try to bear with me and maybe someone will understand (and hopefully clear up) my confusion. My app is a simple hierarchy, of…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
2
votes
1 answer

Better way to optimize/refactor handling nested resources in Rails actions/views?

A friend of mine sent me some code who was having trouble understanding how nested resources work in Rails. Having worked with Rails for many years, I quickly explained it to him and then shared some code. Then I enhanced the code to show him an…
Kevin Elliott
  • 2,630
  • 3
  • 23
  • 21
2
votes
3 answers

Matching records to nested routes in show action

How can you limit the records that are available to the show action? The problem I'm having is that you can manually change the ID in the URL and look at projects that do not belong to the company. My Routes Look like this:…
Aaron Dufall
  • 1,177
  • 10
  • 34
2
votes
1 answer

Best practice for choosing nested resources in Rails?

What criteria do you use to decide whether or not to nest resources? In the past, I have chosen to nest when the index action on a resource makes no sense without scoping to an associated resource (the parent). Even as I write the above criteria, I…
Jay Crouch
  • 141
  • 5
2
votes
1 answer

bizarre routing error though available in rake routes

i have
  • <%= link_to "Messages", user_messages_path %>
  • in my routes.rb i have resources :users do resources :messages member do get :following, :followers end end when i do rake routes, it says.... user_messages GET …
    Sasha
    • 3,281
    • 7
    • 34
    • 52
    1
    vote
    1 answer

    Rails 3.2 - Nested Resource Passing ID

    Okay so my associations are: Outlet -> has_many :monitorings Monitoring -> belongs_to :outlet My Routes: resources :outlets do resources :monitorings end View: <%= link_to new_outlet_monitoring_path(@outlet) %> When I click the link, the logs…
    Ammar
    • 1,091
    • 12
    • 23
    1
    vote
    3 answers

    Controller PUTs both old value and new value?

    The controller does not update seem to know 'where' a post goes when I change the foreign key (in my case topic_id) via a PUT request. I am not entirely sure why this happens, but after struggling with this for a few days I really need some insight.…
    rhodee
    • 1,257
    • 1
    • 14
    • 27
    1
    vote
    0 answers

    Validation with nested resources

    I have two models, Tenant and Property. Property has many Tenants, and Tenant belongs to Property. I want to write a validation that validates the presence of a tenant unless the property is vacant. This is my code: validates :tenants, :presence =>…
    1
    vote
    3 answers

    String resource files in java

    Programming in Java, what's the better way to create resource files to save the messages of the application in different languages? If I use a properties file, inside the code everytime that I need refer to a message I have to write something like…
    user1151835
    1
    vote
    1 answer

    How to pass user_id to nested_resource model?

    I have a small project setup with devise and cancan. There are User, Project, Responsible and Task Models. Project has nested Tasks. Each Project is assigned to one or multiple users. The task model has a name, user_id and project_id. Authentication…
    tonymarschall
    • 3,862
    • 3
    • 29
    • 52
    1
    vote
    2 answers

    Dropping second model name in nested resource route

    I'm using slugs for IDs, so wanting URLs like /songs/radiohead/karma-police instead of /artists/radiohead/songs/karma-police. Slugs can be achieved with: def to_param slug end But how is there any way to drop the model name - "songs" - from the…
    mahemoff
    • 44,526
    • 36
    • 160
    • 222