nested-resources

RESTful API routes design: nested vs. non-nested

こ雲淡風輕ζ 提交于 2019-12-03 05:20:40
My question is about the advantages of nesting resources when building URLs for API purposes. Consider the following two alternatives for accessing an employee resource: /api/employees?department=1 # flat Vs. /api/departments/1/employees # nested Now consider the task of developing a general purpose library to access REST resources from an API. If all routes were flat, such a REST wrapper library would only need to know the name of the resource being accessed: store.query('employees', {department_id:1}) => /api/employees?department=1 However, if we were to support nested routes, this wrapper

Rails Namespace vs. Nested Resource

て烟熏妆下的殇ゞ 提交于 2019-12-03 02:03:09
问题 Let's say my app has two models, Foo and Bar. Foo optionally belongs_to Bar. Right now I can look at a single Foo, or search for a particular Foo, and the FoosController handles all that. My URLS are like: foos/1 and foos/new Sometimes I want to look at a Bar. The BarsController handles that, and I get to it like: bars/1 or bars/1/edit . If I'm looking at a Bar I might want to browse all the Foos that are part of that Bar. So, I'd like to use bars/1/foos/ to look at those Foos. This is pretty

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

拥有回忆 提交于 2019-12-02 21:24:49
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 associations in the models without a problem. My problem lies in how to build the controllers to work with these relationships. I'll try and give an example if you don't see where I'm going with this. For instance... class Account < ActiveRecord::Base has_many :locations end class Contact < ActiveRecord::Base has_many :locations end class Location <

Rails Namespace vs. Nested Resource

人走茶凉 提交于 2019-12-02 17:11:49
Let's say my app has two models, Foo and Bar. Foo optionally belongs_to Bar. Right now I can look at a single Foo, or search for a particular Foo, and the FoosController handles all that. My URLS are like: foos/1 and foos/new Sometimes I want to look at a Bar. The BarsController handles that, and I get to it like: bars/1 or bars/1/edit . If I'm looking at a Bar I might want to browse all the Foos that are part of that Bar. So, I'd like to use bars/1/foos/ to look at those Foos. This is pretty straightforward with nested resources, and it looks like this: resources :foo resources :bar do

Rails 3 - Nested Resources Routing - One to One relationship

╄→尐↘猪︶ㄣ 提交于 2019-12-02 05:36:29
问题 Having some trouble with some nested resources routing. What I'm trying to do is link to a user's profile page for editing purposes. In my view it is written as: <%= link_to "Edit Profile", edit_user_profile_path(current_user) %> Which errors out with: No route matches {:action=>"edit", :controller=>"profiles", :user_id=>#<User id: 1, email: "EDITEDOUT", hashed_password: "EDITEDOUT", created_at: "2011-01-20 18:30:44", updated_at: "2011-01-20 18:30:44">} In my routes.rb file, it looks like so:

Rails 3 - Nested Resources Routing - One to One relationship

我是研究僧i 提交于 2019-12-02 00:26:45
Having some trouble with some nested resources routing. What I'm trying to do is link to a user's profile page for editing purposes. In my view it is written as: <%= link_to "Edit Profile", edit_user_profile_path(current_user) %> Which errors out with: No route matches {:action=>"edit", :controller=>"profiles", :user_id=>#<User id: 1, email: "EDITEDOUT", hashed_password: "EDITEDOUT", created_at: "2011-01-20 18:30:44", updated_at: "2011-01-20 18:30:44">} In my routes.rb file, it looks like so: resources :users do resources :profiles, :controller => "profiles" end I checked my Rake routes, and

How to use will_paginate with a nested resource in Rails?

依然范特西╮ 提交于 2019-12-01 08:43:26
I'm new to Rails, and I'm having major trouble getting will_paginate to work with a nested resource. I have two models, Statement and Invoice. will_paginate is working on Statement, but I can't get it to work on Invoice. I know I'd doing something silly, but I can't figure it out and the examples I've found on google won't work for me. statement.rb class Statement < ActiveRecord::Base has_many :invoices def self.search(search, page) paginate :per_page => 19, :page => page, :conditions => ['company like ?', "%#{search}%"], :order => 'date_due DESC, company, supplier' end end statements

How to use will_paginate with a nested resource in Rails?

﹥>﹥吖頭↗ 提交于 2019-12-01 06:28:12
问题 I'm new to Rails, and I'm having major trouble getting will_paginate to work with a nested resource. I have two models, Statement and Invoice. will_paginate is working on Statement, but I can't get it to work on Invoice. I know I'd doing something silly, but I can't figure it out and the examples I've found on google won't work for me. statement.rb class Statement < ActiveRecord::Base has_many :invoices def self.search(search, page) paginate :per_page => 19, :page => page, :conditions => [

Rails 3 routing: Avoiding Deep Nesting

Deadly 提交于 2019-12-01 04:44:32
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 level deep, so I refactored to this: resources :organisations do resources :studies end resources :studies do resources :settings end Does anyone know a cleaner / more concise way to declare the above routes? Google gave me a lot of Rails 2-specific stuff. Many thanks! You pretty much got it figured out and on the right track. It really depends on your domain.

Rails 3 routing: Avoiding Deep Nesting

别等时光非礼了梦想. 提交于 2019-12-01 01:14:27
问题 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 level deep, so I refactored to this: resources :organisations do resources :studies end resources :studies do resources :settings end Does anyone know a cleaner / more concise way to declare the above routes? Google gave me a lot of Rails 2-specific stuff.