Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 739121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:21:49+00:00 2026-05-14T08:21:49+00:00

I’m a newbie Rails developer who is getting the following error when trying to

  • 0

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 class="field">

As some background, I have a State model with many Cities. I’m getting this error after clicking on the following link coming from a State show page:

<p>Add a city: <%= link_to "Add city", new_state_city_path(@state) %></p>

When I run ‘rake:routes’ it says this is a legit route…

For more background, here is the CityController ‘new’ action:

def new
@city = City.new

respond_to do |format|
  format.html # new.html.erb
  format.xml  { render :xml => @city }
end
end

Here is the (complete) form in the view:

<%= form_for(@city) do |f| %>
<%= f.error_messages %>

<div class="field">
  <%= f.label :name %><br />
  <%= f.text_field :name %>
</div>
<div class="actions">
  <%= f.submit %>
</div>
<% end %>

This initially made me think that it’s a resources/routes issue since it came back with a mention of ‘cities_path’ (in fact, that’s what another person posting to Stack Overflow had wrong (Rails error "NoMethodError" – My first ruby app). However, that doesn’t seem to be the case from what I can see. Here are how my resources look in my routes file:

resources :states do
  resources :cities
end

I can get it working when they are not sub-resources, but I really need to keep them as sub-resources for my future plans with the app. Any help would be very much appreciated, since I’ve been racking my brains on this for more hours than I would care to admit… Thanks!

(Not sure this matters at all, but I’m running the very latest version of Rails 3 beta2).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:21:50+00:00Added an answer on May 14, 2026 at 8:21 am

    Your problem is coming from line 2 of your view above, specifically the form_for declaration. As you pointed out, state_city_path is a valid path, but right now, your form is not using this path, it’s using city_path. When using nested resources, you need to define everything in terms of that nesting. Your form_for should look something like form_for([@state, @city]) do (I don’t remember the exact syntax).

    Your follow up answer will work, but isn’t exactly the best way to go about it, unless you want to be able to look at cities that are not in the context of a state.

    Hope this helps.

    PS. The form_for documentation is pretty good, and shows some good examples when using it with resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.