Chris T wrote:
Mike Garey wrote:
> sorry I can't provide much assistance for this question, but I thought
> I'd also mention that I'm very interested in knowing how others have
> solved this.. It seems to be one of the sore points that I've come
> across when switching my controllers to support rest.
>
> Whereas before I used to have all the admin related tasks in my admin
> controller, I've now tried to put them into my (for example), products
> controller, but there's times when I want the index for a regular user
> to show one view and the index for the admin to show a more condensed
> view that's easier to navigate and edit entries.
>
> So far what I've done to solve this is to use an "admin_index" action
> in my controller, as well as an admin_index.rhtml file in my views
> directory, and then put the following in my routes file:
>
> map.resources :products, :collection => { :admin_index => :get}
>
> but I was wondering if anyone has a better method for accomplishing this..
>
> in the restful rails peepcode screencast
> (Online Courses, Learning Paths, and Certifications - Pluralsight), they briefly
> touch upon adding an administrative interface by using different
> layouts, however, I don't see how this works when you have more than a
> single action that needs both a public and an administrative view
> (plus, if you used a separate layout for each admin action, you'd
> quickly find yourself with a whole mess of layouts)
>
> the other alternative would be to keep the rest controllers the way
> they are, but then still use an admin controller to provide the
> administrative interface for the objects. But then you'll end up
> splitting your code between two controllers for a single object type,
> which kinda goes against the notion of encapsulating all the methods
> for a certain object in its own controller.
>
> Anyone else have any thoughts on this topic? Would like to hear how
> others are tackling this problem..
>
> Mike
>
>
>> Hello,
>>
>> I want to seperate my admin and public views but only use one
>> controller. How to seperate layouts ist clear but how can I tell the
>> controller to render the *.rhtml files in views/admin/ when logged in or
>> render the *.rhtml files in views/public/ (for example).
>>
>> Thanks for any help!
>>
>> PS: using REST and CRUD in edge rails
>>
>>
>
> >
>
>
Think there's a number of ways of skinning this, but for me I kept the
admin actions in the relevant REST controller (update & destroy, and for
some controllers create too), but restricted access to them to admin
users with a filter, then had an admin controller with a single index
method, which acted as a dashboard, and a jumping off point for the
other actions.
That way the REST actions stay in the correct controllers, but the admin
controller does just the only job it's supposed to, which is to acts as
an admin front page. I considered splitting the main front page index,
so it acted as the admin index for admin users, normal for other users,
but then decided that there were times that admins would want to see the
front page other users saw without having to log out to do it.
Just my $0.02. YMMV
Hi,
Have a look at the route below ...
map.resources :coupons, :path_prefix => ':locale/admin', :controller
=> 'admin/coupons', :name_prefix => 'admin_', :collection => { :sort =>
:post }, :member => { :status => :put }
which yields example named routes: admin_coupons_url(),
admin_sort_coupons_url(), admin_new_coupon_url() etc.
You may also do the following, in coexistence with the above:
map.resources :coupons, which yields non-namespaced equivalent, only
difference being the admin_* prefix to named routes is dropped.
I'll do a short writeup on my blog about this soon, as plenty folks is
affected in the migration to more RESTful codebases.
Lourens Naude
http://blog.methodmissing.com