Romain ''Maz'' BILLOIR
2011-Sep-13 21:47 UTC
mywebsite/admin/categories point to show.html.erb?
Hi everyone, I''m having some troubles with RoR and REStful
controllers:
I generated a simple scaffold "categories" wich contains name and
branch column: easy.
I also generated a namespaced controller "admin/categories".
I replaced all the scaffold''s link_path in my views to match with my
admin namespace, such as "<%= link_to ''Show'',
@category %>" became "<
%= link_to ''Show'', [:admin, @category] %> ".
I replace the resource routes with my namespace:
namespace :admin do
resources :categories
end
And everything works fine... Until I created a resource in my database
using scaffold forms... Now when I''m going to "mywebsite/admin/
categories", rails is trying to render show method:
No route matches {:action=>"show",
:controller=>"admin/categories"}
I search on the web to fix and found this:
http://www.ruby-forum.com/topic/145160
But I didn''t really understand how to fix the problem.
Can someone help me? =)
Regards,
Romain ''Maz'' B.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
What version of Rails are you using? Can you post your entire routes.rb file? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/MXvrpF82IoEJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Romain ''Maz'' BILLOIR
2011-Sep-14 16:04 UTC
Re: mywebsite/admin/categories point to show.html.erb?
I''m using rails 3.1.0 on ruby 1.9.2. my routes.rb just contains the admin namespace and a root_to which points to application#index. I''ll post rake routes as soon I can if it''s necessary -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 13 September 2011 22:47, Romain ''Maz'' BILLOIR <billoirr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi everyone, I''m having some troubles with RoR and REStful > controllers: > > I generated a simple scaffold "categories" wich contains name and > branch column: easy. > I also generated a namespaced controller "admin/categories". > I replaced all the scaffold''s link_path in my views to match with my > admin namespace, such as "<%= link_to ''Show'', @category %>" became "< > %= link_to ''Show'', [:admin, @category] %> ". > I replace the resource routes with my namespace: > > namespace :admin do > resources :categories > end > > And everything works fine... Until I created a resource in my database > using scaffold forms... Now when I''m going to "mywebsite/admin/ > categories", rails is trying to render show method: > No route matches {:action=>"show", :controller=>"admin/categories"}When you say that it is trying to *render* the show method do you mean that is during running the index action? Is the render being invoked from the index action? Have a look in the rails log. If you can''t see what is happening then post the log starting with what happens when you click the link. You also might like to have a look at the rails guide on debugging. That will show you how to use ruby-debug to break into your code and see what is going on. So you can break into the index action (assuming it is getting there) and inspect data and follow the flow to see what is happening. Colin -- gplus.to/clanlaw -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Romain ''Maz'' BILLOIR
2011-Sep-14 21:17 UTC
Re: mywebsite/admin/categories point to show.html.erb?
No, this is what''s happening:
when i typed for the first time /admin/categories, it rendered me the
empty list of categories. I clicked the New link, rendered the add
form, submit the form rendered the new category, click the Return link
which is /admin/categories, performed show action. WHY?
If i delete the entry in my database, /admin/categories performs index
action like it should. WHY²?
Here is my log:
Started GET "/admin/categories" for 127.0.0.1 at 2011-09-14 23:16:04
+0200
Processing by Admin::CategoriesController#index as HTML
[1m [36mCategory Load (0.5ms) [0m [1mSELECT "categories".* FROM
"categories" [0m
Rendered admin/categories/index.html.erb within layouts/application
(19.3ms)
Completed 200 OK in 120ms (Views: 117.5ms | ActiveRecord: 0.5ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at
2011-09-14 23:16:05 +0200
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:05 +0200
Served asset /jquery.js - 304 Not Modified (6ms)
Started GET "/assets/categories.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:05 +0200
Served asset /categories.js - 304 Not Modified (2ms)
Started GET "/assets/admin/categories.js?body=1" for 127.0.0.1 at
2011-09-14 23:16:05 +0200
Served asset /admin/categories.js - 304 Not Modified (2ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at
2011-09-14 23:16:05 +0200
Served asset /application.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:05 +0200
Served asset /jquery_ujs.js - 304 Not Modified (4ms)
Started GET "/admin/categories/new" for 127.0.0.1 at 2011-09-14
23:16:06 +0200
Processing by Admin::CategoriesController#new as HTML
Rendered admin/categories/_form.html.erb (24.0ms)
Rendered admin/categories/new.html.erb within layouts/application
(38.3ms)
Completed 200 OK in 48ms (Views: 44.7ms | ActiveRecord: 2.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at
2011-09-14 23:16:06 +0200
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:06 +0200
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:06 +0200
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/admin/categories.js?body=1" for 127.0.0.1 at
2011-09-14 23:16:06 +0200
Served asset /admin/categories.js - 304 Not Modified (0ms)
Started GET "/assets/categories.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:06 +0200
Served asset /categories.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at
2011-09-14 23:16:06 +0200
Served asset /application.js - 304 Not Modified (0ms)
Started POST "/admin/categories" for 127.0.0.1 at 2011-09-14 23:16:16
+0200
Processing by Admin::CategoriesController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"PVlLpCPYEhLre3tsFlYRQdVnbbySI2Gw/YSCEuzjnWo=",
"category"=>{"name"=>"vaze",
"branch"=>"Project"}, "commit"=>"Create
Category"}
[1m [35m (0.3ms) [0m BEGIN
[1m [36mSQL (24.0ms) [0m [1mINSERT INTO "categories"
("branch",
"created_at", "name", "updated_at") VALUES ($1,
$2, $3, $4) RETURNING
"id" [0m [["branch", "Project"],
["created_at", Wed, 14 Sep 2011
21:16:16 UTC +00:00], ["name", "vaze"],
["updated_at", Wed, 14 Sep
2011 21:16:16 UTC +00:00]]
[1m [35m (12.0ms) [0m COMMIT
Redirected to http://127.0.0.1:3000/admin/categories/7
Completed 302 Found in 51ms
Started GET "/admin/categories/7" for 127.0.0.1 at 2011-09-14 23:16:16
+0200
Processing by Admin::CategoriesController#show as HTML
Parameters: {"id"=>"7"}
[1m [36mCategory Load (0.8ms) [0m [1mSELECT "categories".* FROM
"categories" WHERE "categories"."id" = $1 LIMIT 1
[0m [["id", "7"]]
Rendered admin/categories/show.html.erb within layouts/application
(7.1ms)
Completed 200 OK in 25ms (Views: 16.6ms | ActiveRecord: 4.1ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at
2011-09-14 23:16:16 +0200
Served asset /application.css - 304 Not Modified (0ms)
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:16 +0200
Served asset /jquery.js - 304 Not Modified (0ms)
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:16 +0200
Served asset /jquery_ujs.js - 304 Not Modified (0ms)
Started GET "/assets/categories.js?body=1" for 127.0.0.1 at 2011-09-14
23:16:16 +0200
Served asset /categories.js - 304 Not Modified (0ms)
Started GET "/assets/admin/categories.js?body=1" for 127.0.0.1 at
2011-09-14 23:16:16 +0200
Served asset /admin/categories.js - 304 Not Modified (0ms)
Started GET "/assets/application.js?body=1" for 127.0.0.1 at
2011-09-14 23:16:16 +0200
Served asset /application.js - 304 Not Modified (0ms)
Started GET "/admin/categories" for 127.0.0.1 at 2011-09-14 23:16:18
+0200
Processing by Admin::CategoriesController#index as HTML
[1m [35mCategory Load (0.3ms) [0m SELECT "categories".* FROM
"categories"
Rendered admin/categories/index.html.erb within layouts/application
(39.4ms)
Completed 500 Internal Server Error in 52ms
ActionView::Template::Error (No route matches
{:action=>"show", :controller=>"admin/categories"}):
13: <tr>
14: <td><%= category.name %></td>
15: <td><%= category.branch %></td>
16: <td><%= link_to ''Show'',
admin_category_path(@category) %></
td>
17: <td><%= link_to ''Edit'',
edit_admin_category_path(@category) %></td>
18: <td><%= link_to ''Destroy'',
admin_category_path(@category),
confirm: ''Are you sure?'', method: :delete %></td>
19: </tr>
app/views/admin/categories/index.html.erb:16:in `block in
_app_views_admin_categories_index_html_erb___936809880_79782210''
app/views/admin/categories/index.html.erb:12:in `each''
app/views/admin/categories/index.html.erb:12:in
`_app_views_admin_categories_index_html_erb___936809880_79782210''
app/controllers/admin/categories_controller.rb:7:in `index''
Rendered /usr/lib/ruby/gems/1.9.1/gems/actionpack-3.1.0/lib/
action_dispatch/middleware/templates/rescues/routing_error.erb within
rescues/layout (0.8ms)
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Romain ''Maz'' BILLOIR
2011-Sep-14 22:13 UTC
Re: mywebsite/admin/categories point to show.html.erb?
Okay, i just fixed the problem.
In index.html.erb to display link i used this:
<td><%= link_to ''Show'',
admin_category_path(@category) %></td>
<td><%= link_to ''Edit'',
edit_admin_category_path(@category) %></
td>
<td><%= link_to ''Destroy'',
admin_category_path(@category),
confirm: ''Are you sure?'', method: :delete %></td>
which is the default generated link by scaffold, just added "admin_".
But the problem come from the @category, if i delete the @:
<td><%= link_to ''Show'',
admin_category_path(category) %></td>
<td><%= link_to ''Edit'',
edit_admin_category_path(category) %></td>
<td><%= link_to ''Destroy'',
admin_category_path(category), confirm:
''Are you sure?'', method: :delete %></td>
Everything works fine!
Thanks a lot!
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.