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

  • Home
  • SEARCH
  • 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 8484769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:27:55+00:00 2026-06-10T20:27:55+00:00

I’m facing a problem with a nested route in Rails an I can’t figure

  • 0

I’m facing a problem with a nested route in Rails an I can’t figure out, what I’m doing wrong.

In a nutshell: I use Devise for authentication an registration. Now I want to have the user enter more detailed information about his contact data. To keep the user model small, I want to use a different model called account. As a user only will have one account, I use a on-to-one association and a nested route. But somehow the routing does not work.
This is my user model:

user.rb

class User < ActiveRecord::Base
  has_one :account, :dependent => :destroy
  attr_accessible :username, :email, :password, :password_confirmation, :remember_me

and this is my account model:

account.rb

class Account < ActiveRecord::Base
 attr_accessible :anrede, :land, :nachname, :plz, :stadt, :strasse, :user_id, :vorname
 belongs_to :user
end

and my route file looks like this:

routes.rb

devise_for :users, :path => 'members'
 resources :users do
  resource :account
 end

As a user might not have a account yet, I test this in my view:

        <% if current_user.account.try %>
        <li><%= link_to "Account", user_account_path %></li>
        <% else %>
        <li><%= link_to "create Account", new_user_account_path %></li>
        <% end %>

but when I enter the root path with a signed in user, Rails tells me

Routing Error
No route matches {:action=>"new", :controller=>"accounts"}

but there is a new action in my accounts_controller.rb as I have scaffolded the whole CRUD set (edited create with current_user.build_account) and it’s also the path given by rake routes.

I’m desperately stuck in this! Could anybody help me, please?

EDIT
This is the output of my rake routes:

        user_account POST   /users/:user_id/account(.:format)      accounts#create
    new_user_account GET    /users/:user_id/account/new(.:format)  accounts#new
   edit_user_account GET    /users/:user_id/account/edit(.:format) accounts#edit
                     GET    /users/:user_id/account(.:format)      accounts#show
                     PUT    /users/:user_id/account(.:format)      accounts#update
                     DELETE /users/:user_id/account(.:format)      accounts#destroy

EDIT2

this is the error message for the action new form:

NoMethodError in Accounts#new

Showing /home/stonjarks/Work/toytrade_devise/app/views/accounts/_form.html.erb where line #1 raised:

undefined method `accounts_path' for #<#<Class:0xa44d0cc>:0xab6222c>

Extracted source (around line #1):

1: <%= form_for(@account) do |f| %>
2:   <% if @account.errors.any? %>
3:     <div id="error_explanation">
4:       <h2><%= pluralize(@account.errors.count, "error") %> prohibited this account from being saved:</h2>

I solved this using this SO hack, but it’s a strange behavior anyway:

Rails Nested Route For Singular Resource

<%= form_for @account,:url=>{:action=>:create}

But I still don’t get the point of this routing anyway. Despite this, I can’t manage to find a route to show the account:

/users/1/account

ActiveRecord::RecordNotFound in AccountsController#show

Couldn't find Account without an ID
  • 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-06-10T20:27:57+00:00Added an answer on June 10, 2026 at 8:27 pm

    new_user_account_path is missing a user instance which should be provided for example:

    new_user_account_path(current_user)

    If you look at the following line:

    new_user_account GET    /users/:user_id/account/new(.:format)  accounts#new
    

    You can see that the path demands a :user_id – a user instance.

    You can read here for further clarification of your problem.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
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
I have a jquery bug and I've been looking for hours now, I can't
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 am doing a simple coin flipping experiment for class that involves flipping a
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 know there's a lot of other questions out there that deal with this

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.