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 8547867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:21:41+00:00 2026-06-11T13:21:41+00:00

I have worked with rails scaffold to generate forms and views automatically. But now

  • 0

I have worked with rails scaffold to generate forms and views automatically.
But now I had to use namespaced controller with model in root namspace.

So, I generated controller manually without scaffold, I’m having trouble working with form.

I suppose that the following code should generate a form for namespaced controller

<%= form_for @menu do |f| %>

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

but it doesnt. it says

undefined method `model_name' for NilClass:Class

it seems very easy to do rails with scaffold generators, but if one wants to do manually, rails helper method turns negative on them.

I have searched for form_for documentation and changed the code to

<%= form_for @menu, :url => admin_menu_path do |f| %>

then it shows a different error that

No route matches {:action=>"show", :controller=>"admin/menus"}

my rake routes gives the following output

     admin_root        /admin(.:format)                admin/menus#index
    admin_menus GET    /admin/menus(.:format)          admin/menus#index
                POST   /admin/menus(.:format)          admin/menus#create
 new_admin_menu GET    /admin/menus/new(.:format)      admin/menus#new
edit_admin_menu GET    /admin/menus/:id/edit(.:format) admin/menus#edit
     admin_menu GET    /admin/menus/:id(.:format)      admin/menus#show
                PUT    /admin/menus/:id(.:format)      admin/menus#update
                DELETE /admin/menus/:id(.:format)      admin/menus#destroy

correct me if I’m wrong, but I think ruby cannot find model Menu in Admin namespace, which is obvious. So, I tried with ::Menu.new , I thought it would look up in upper namespace, but no result!

  • 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-11T13:21:43+00:00Added an answer on June 11, 2026 at 1:21 pm

    You might be forgetting to instantiate @menu in your controller.

    The message “undefined method ‘model_name’ for NilClass:Class” says that @menu is nil.

    Since admin_menu_path needs a Menu instance, Rails cannot generate the route correctly when nil is passed.

    Once you have the instance variable properly set in your controller you can use:

    form_for [:admin, @menu] do |f| ... end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely new to Ruby on Rails, have never worked on it, but I
I have the following which worked in Rails 2.3.8: /lib/trimmer.rb I use it in
i have worked for a year now , on server side applications and everytime
I have worked within a web development company where we had our local machines,
I have worked with pointers a lot, but still whenever I work with them,
I have worked many projects with no problems. But in current project, I tested
Initially I ran rails g scaffold Post title:string content:text and after migrating everything worked
I am new to MVC .NET (I have previously worked on Ruby On Rails).
I was using only html emails which worked from my Rails 3.1.4 app, but
I have setup this HABTM relationship in the past and it has worked before....Now

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.