I'm creating a blog with Rails and the first thing that I've done is the administration area (by now is the only thing I have in the application). I've used Bootstrap to quickly design all the pages and Devise for authentication.
For all the models, views and controllers I used scaffolding and I generated both Admin and Post models.
The problem is that now I have to create the REAL blog and access the administration panel using /admin route. For example, to create a new post I should access http:/mysite/admin/posts/new.
Another problem is that I will have a totally different design in the public blog page (not Bootstrap) and of course I'll have different controllers, views and routes.
So, what can be done?
I would suggest removing the Admin model as in your case it seems more like a namespace than a model. I would instead create an :admin namespace in your routes.rb file like:
namespace :admin do
resources :posts
end
This will cause all routes inside of this block to be prefixed w/ admin. So the URL for editing a post on the admin side would be admin/posts/:id/edit.
Next I would suggest making an AdminController that all of your admin controllers will inherit from. This way you can specify a new layout. Then you can create a Admin::PostsController at app/controllers/admin/posts_controller.rb
app/controllers/admin_controller.rb
class AdminController < ApplicationController
layout 'admin'
end
app/controllers/admin/posts_controller.rb
class Admin::PostsController < AdminController
def index
# admin/posts
end
end
app/views/admin/posts/index.html.erb
Hello from the admin/posts view!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With