nested-resources

Rails nested resources

Here's the routes.rb: map.resources :assignments, :shallow => true do |assignment| assignment.resources :problems end How do i get the url to edit a problem (/assignments/xyz/problems/abc/edit), in code? I have tried both edit_assignment_problem_path(assignment,problem) and edit_problem_path(problem). While the firs...

Rails nested routing to html id

given a blog style application: #models class Post < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :post end #routes.rb map.resources :posts do |posts| posts.resources :comments end how do I generate routes to an id on a page? Examples /posts/1#comments /posts/2#comment14 ...

How to use will_paginate with a nested resource in Rails?

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. ...

With nested routes does the parent controller or the child controller process the request for the "new" action?

If you have a nested resource defined like this: map.resources :magazines, :has_many => :ads. for these models: class Magazine < ActiveRecord::Base has_many :ads end class Ad < ActiveRecord::Base belongs_to :magazine end When you invoke this url: /magazines/1/ads/1/new with the nested route helper: new_magazine_ad_pa...

Rails - link_to, routes and nested resources

As my understanding on nested resources, on edge Rails, should not link_to 'User posts', @user.posts point to /users/:id/posts ? The routes.rb file contains map.resources :users, :has_many => :posts If this is not the default behavior, can it be accomplished doing something else? ...

Multiple Nested Routes, is there a better way to do this?

So In my rails app I have two resources (rentals, and reservations) which belong to a user. This is the code in my routes.rb to set up the nested routes. map.resources :users, :has_many => :reservations, :shallow => true map.resources :users, :has_many => :rentals, :shallow => true map.resources :rentals, :only => [:index] map....

Rails: Nested resources conflict, how to scope the index action depending on the called route

Imagine you have two defined routes: map.resources articles map.resources categories, :has_many => :articles both accessible by helpers/paths articles_path # /articles category_articles_path(1) # /category/1/articles if you visit /articles, index action from ArticlesController is executed. if you visit /category/1/articles, index ...

Nested Layout for Nested Resources in Rails

Is it possible to automatically assign a specified layout template to a particular controller and all of the resources nested within it, as specified in routes.rb? This layout should apply only the specified controller views and those nested within it; it does not need to be applied to every view within the application, as application.ht...

form_for with nested resources

I have a two-part somewhat noob question about form_for and nested resources. Let's say I'm writing a blog engine and I want to relate a comment to an article. I've defined a nested resource as follows: map.resources :articles do |articles| articles.resources :comments end The comment form is in the show.html.erb view for articles...

Nested routes with Subdomain-fu

I have some standard nested routes in my app, and I want to implement subdomains using the subdomain-fu gem. So I'm currently doing this: example.com/stores/name_of_store/products/name_of_product and I want to do this: name_of_store.example.com/products/name_of_product There seems to have been some discussion about the failing...

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 this: map.resources :products # /products map.resources :events do |event| event.resources :product...

Nested Resource testing RSpec

I have two models: class Solution < ActiveRecord::Base belongs_to :owner, :class_name => "User", :foreign_key => :user_id end class User < ActiveRecord::Base has_many :solutions end with the following routing: map.resources :users, :has_many => :solutions and here is the SolutionsController: class SolutionsC...

RSpec, stubbing nested resource methods

I've got two models: class Solution < ActiveRecord::Base belongs_to :owner, :class_name => "User", :foreign_key => :user_id end class User < ActiveRecord::Base has_many :solutions end and I nest solutions within users like this: ActionController::Routing::Routes.draw do |map| map.resources :users, :has_many => :solutions end ...

Rails "NoMethodError" with sub-resources

Hi. I'm a newbie Rails developer who is getting the following error when trying to access the 'new' action on my CityController: undefined method `cities_path' for #<#<Class:0x104608c18>:0x104606f08> Extracted source (around line #2): 1: <h1>New City</h1> 2: <%= form_for(@city) do |f| %> 3: <%= f.error_messages %> 4: 5: <div clas...

Finds in Rails 3 and ActiveRelation

Guys, I'm trying to understand the new arel engine in Rails 3 and I've got a question. I've got two models, User and Task class User < ActiveRecord::Base has_many :tasks end class Task < ActiveRecord::Base belongs_to :user end here is my routes to imply the relation: resources :users do resources :tasks end and here is my ...

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

Hey guys, I've 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 Payment < ActiveRecord::Base belongs_to :project accepts_nested_attributes_for ...

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 :tickets end resources :events do resources :tickets end How do I scope my ticket_Cont...

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 with rails3 yet as I would like), and comments are an embedded resource (mongoid can't yet ha...

How to add aditional rest routes to a nested resource in rails

I have a widget that has many links. In the routes file: map.resources :widgets, :has_many => [:links] I want to add a "sort" action to links. What do I need to add to the routes file, so I can write sort_widget_links_path(widget) Thanks, Deb ...

Rails 3 - Error Validation on nested resource

I'm really struggling with how to handle Error Handling in Rails 3. I have hacked some ideas that could work but would rather do it the proper way. If anyone can help or give guidance I would appreciate it. Here is what I have so far ItemController def show @item = Item.find(params[:id]) @note = @item.notes.new respond_w...