Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to handle form_for in rails namspaced controller
    primarykey
    data
    text
    <p>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.</p> <p>So, I generated controller manually without scaffold, I'm having trouble working with form.</p> <p>I suppose that the following code should generate a form for namespaced controller</p> <pre><code>&lt;%= form_for @menu do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :label %&gt;&lt;br /&gt; &lt;%= f.text_field :label %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :order %&gt;&lt;br /&gt; &lt;%= f.text_field :order %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>but it doesnt. it says </p> <pre><code>undefined method `model_name' for NilClass:Class </code></pre> <p>it seems very easy to do rails with scaffold generators, but if one wants to do manually, rails helper method turns negative on them.</p> <p>I have searched for form_for documentation and changed the code to</p> <pre><code>&lt;%= form_for @menu, :url =&gt; admin_menu_path do |f| %&gt; </code></pre> <p>then it shows a different error that</p> <pre><code>No route matches {:action=&gt;"show", :controller=&gt;"admin/menus"} </code></pre> <p>my rake routes gives the following output</p> <pre><code> 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 </code></pre> <p>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!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload