Forum: Ruby on Rails problematic admin/views

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ana B. (Guest)
on 2006-04-27 05:19
ok, i have a pretty almost finished (frontend) blog, i have defined an
admin zone with authentication to add content, now im getting trouble
with the views for the controllers in the admin zone, here you can see
my file structure:
http://img284.imageshack.us/my.php?image=tmpviews6oq.gif

and my admin controllers like this:

controllers/admin/admin_controller.rb
class Admin::AdminController < ApplicationController
...
end

controllers/admin/articles_controller.rb
class Admin::ArticlesController < Admin::AdminController
...
end

both works fine, the problem are the views, for example the
controllers/articles_controller.rb takes the view from
views/layouts/articles.rhtml no problem, so the
controllers/admin/articles_controller.rb should take the view from but
views/admin/layouts/articles.rhtml but isnt taking any view¡¡ not from
there not from any place or folder in the admin view zone that i put the
articles.rhtml file.

but it does take the little files that are usually called from
@content_for_layout(show.rhtml, edit.rhtml, etc.) so i can add,delete,
edit items without problems(if i see the source html of the browser i
only see this part of htmlcode not a complete html page) but what is
happening, why arent taking a main view?

note: the problem its present on every controller that i create on the
admin zone, and when i create the admin/articles_controller.rb the
views/layouts/articles.rhtml(the frontend controller view) its
overwritten(why¡?).

well,i have been working on this for a while and now im clueless about
this, hope someone acn help with this, any help will be very apreciated.

:)
Alex W. (Guest)
on 2006-04-27 06:01
So the views that work for Admin::ArticlesController are in
"app/admin/articles/*.rhtml" and the ones that don;t work are in
"app/admin/*.rhtml"

Views for ArticlesController: app/views/articles
Views for Admin::ArticlesController: app/views/admin/articles

See how that works?

As for the layout, I don't believe you can put layouts in a subfolder
like that.  I think the only layouts treated as layouts are in
"app/views/layouts"

So create a file called "admin_articles.rhtml" in "app/views/layouts",
and then in your Admin::ArticlesController put this near the top

  layout: admin_articles
Ana B. (Guest)
on 2006-04-27 08:46
by the naming conventions that are so mentioned, and using simple logic
i thought that if a controller created in /controllers have its main
view on /views/layouts, then a controller created on /controllers/admin
will have its view on /views/admin/layout but well, weird rails thing.

now my layouts worked defining layout: admin/articles(i have
articles.rhtml inside  /views/admin).

Many thanks for this Alex ;)
This topic is locked and can not be replied to.