Rails - Debugging Nested Routes

I have 2 models, Assessments and Questions. Assessments have many questions.

In routes, I have:

map.resources :assessments, :has_many => :questions map.root :assessments

I checked rake routes, it's as expected

On the form to create a new question, I get the following error:

undefined method `questions_path' for #<ActionView::Base:0x6d3cdb8>

If I take out the form, the view loads fine, so I think it's something with the code in this view - I'm getting the error on the form_for line:

<h1>New question</h1> <% form_for [@assessment, @question] do |f| %> <%= f.error_messages %> <p> <%= f.label :content %><br /> <%= f.text_field :content %> </p> <p> <%= f.submit 'Create' %> </p> <% end %> <%= link_to 'Cancel', assessment_path(@assessment) %>

Rake Routes - http://pastebin.com/6fKUPTjq

Code to question controller - http://pastebin.com/URzpmEcg

Code to assessment controller - http://pastebin.com/HstvFTq4

Can anyone help me debug it? Thanks!

-------------Problems Reply------------

You need to have

@assessment = Assessment.find(params[:assessment_id])

in the controller. Otherwise, @assessment is nil.

Category:ruby on rails Views:0 Time:2010-06-09

Related post

  • Rails 3 - Nested Routes- Help Requested 2010-10-26

    Here is my Rails 3 nested routes structure for PROJECT resources :projects do resources :notes, :photos collection do get 'yourproject', 'newjs' end end This works great for things like /projects /projects/1 /projects/1/notes/ /projects/1/notes/3 wha

  • Rails 3 nested routes controller access 2010-11-27

    I have a nested route as: resources :wsps do member do get :location get :password end resources :services end I can access all the paths (e.g: new_wsp_service_path) via de services views and services controller, however, I cannot do the same using t

  • rails pagination nested routes 2010-11-24

    I am attempting to put a contacts paginated partial inside of a view for rooftops. Rooftops has many contacts and also has a nested route allowing /rooftops/1/contacts. When I try to create the will_paginate links I get /rooftops/1 as the path rather

  • Rails 3 / nested routes: Problem to redirect to the correct url for a collection of microposts in a user show page 2011-03-23

    I have a problem with nested routes which don't display correct url. I use the below code, but it renders something like: .../users/[:user_id]/microposts/[:user_id] instead of: .../users/[:user_id]/microposts/[:micropost_id] for every microposts disp

  • REST Rails 2 nested routes without resource names? 2010-06-11

    I'm using Rails 2. I have resources nested like this: - university_categories - universities - studies - professors - comments I wish to use RESTful routes, but I don't want all that clutter in my URL. For example instead of: /universities/:universit

  • Rails 3 nested routes question 2011-08-29

    I need some help with routes. Here are my current routes. resources :users, :only => [:index, :show, :create, :destroy] do resources :links, :only => [:create, :destroy], :shallow => true, :on => :member end and when I run rake routes I g

  • Rails 3 nested routes parameter names different 2012-01-20

    I have a nested resource that looks like this: resources :events resources :attendances post 'update_email' end end and it shows me routes that look like this (left out most of the standard REST routes for brevity): event_attendance GET /events/:even

  • Rails 3 Nested Routing 2012-03-01

    I have very interesting scenario: I've specified two controllers, one for global events and another another once for company specific events. In routes, it is specified like this: resources :companies do resources :events end resources: events Runnin

  • Why does Rails 3 nested route ignore nesting resource? 2012-04-11

    Associations: location has_many :comments comment belongs_to :location For some reason, this GET: /locations/5/comments.json is acting like this GET: /comments.json Started GET "/locations/5/comments.json" for at 2012-04-10 21:18:00 -0700 P

  • rails 3 nested routing error 2011-08-25

    my routes.rb TerritoryManagement::Application.routes.draw do resources :addresses resources :territories, :shallow => true do resources :addresses end end rake routes says $ rake routes addresses GET /addresses(.:format) {:action=>"index", :con

  • Nested Routes and Parameters for Rails URLs (Best Practice) 2009-11-20

    I have a decent understanding of RESTful urls and all the theory behind not nesting urls, but I'm still not quite sure how this looks in an enterprise application, like something like Amazon, StackOverflow, or Google... Google has urls like this: htt

  • Tell if a controller is being used in a nested route in Rails 3 2010-11-08

    I made a nested route in a Ruby on Rails 3 project. with the following routing: resources :companies do resources :projects end now I can get to the project contoller's index method via example.com/projects/id or example.com/companies/id/projects/id,

  • Functional tests of nested routes on Rails 3 2010-12-18

    I have a Rails 3 app with the following nested route: resources :games do collection do get :all get :unassigned end resources :messages resources :comments end A Game has many comments, and a Game also has many messages. I am expecting that "/games/

  • Using nested routes Rails 3 without actually allowing access to the parent resource 2011-03-15

    I'm using Rails 3 and I have two models EquipmentGroup and Reservation. I want reservations to be a nested resource of equipment groups so that I can access them with URLs like: /equipment_groups/:equipment_group_id/reservations/:id However, I don't

  • Rails 3 form_for Nested Routes 2011-06-02

    I`m trying to do a form_for with nested routes following the example of Blog and Comments from Ruby Guide(http://guides.rubyonrails.org/getting_started.html#adding-a-route-for-comments). I`m doing an application to create surveys with a lot of kind o

  • Nested Routes Broken: Rails 3 2012-02-06

    I'm having a devil of a time getting this particular nested route to work. It's odd, because I've been migrating a number of routes to the new Rails 3 syntax and this one in particular just doesn't seem to work. Here goes. I've got an object called "

  • Rails trying to create nested routes 2013-01-29

    Ok i'm shooting to have a url like this /applications/:application_id/jobseekers/new. I know if i generate 2 scaffolds (applications and jobseekers) i could make the routes work by doing this: resources :applications do resources :jobseekers end but

  • Rails Nested Route For Singular Resource 2009-07-21

    I have a nested route on a singular resource map.resource :account, :controller => "users" do |page| page.resources :feeds end I'm trying to make a form to add a feed. I start with this... <% form_for @feed do |f| %> undefined method `feeds_

  • Rails: what are the benefits of using nested routes / forms 2010-05-07

    I am starting to use some nested routes which is definitely a different way of planning things and I'm really failing to see added benefits. So what are they? --------------Solutions------------- It allows you stay Restful and automatically route url

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.178 (s). 11 q(s)