I'm using restful_authentication and I would like to have diferent views
for logged users and not logged users. Logged users can edit and create
items, and not logged user could only list items and show its features.
In my routes file I have:
map.namespace :admin do |admin|
map.resources :items, :controller => "admin/items", :path_prefix =>
'admin'
end
map.resources :items
In my views I have:
<%= link_to '<b>Items</b>', items_path %>
The link_to always redirect to admin/item/index (except if I change the
order in routes.rb, if I do always redirect to item/index).
Is it possible to redirect admin/item/index when user is logged in and
redirect to item/index when user is not logged in?
Please replace it with Authlogic or Devise as soon as possible.
restful_authentication is hard to work with due to its reliance on
unmaintainable generated code.
and I would like to have diferent views
for logged users and not logged users. Logged users can edit and create
items, and not logged user could only list items and show its features.
In my routes file I have:
map.namespace :admin do |admin|
map.resources :items, :controller => "admin/items", :path_prefix =>
'admin'
end
map.resources :items
In my views I have:
<%= link_to '<b>Items</b>', items_path %>
The link_to always redirect to admin/item/index (except if I change the
order in routes.rb, if I do always redirect to item/index).
Is it possible to redirect admin/item/index when user is logged in and
redirect to item/index when user is not logged in?
Sure. You could test current_user and build the link accordingly. But
I'd recommend against doing this. Instead, have a separate "admin
login" link on the items index page. That way you don't have to be
checking logins all the time.
I don't understand what you mean with "admin login"... There is only one
user who can create, edit and delete. This user is the admin. The other
"users" aren't users at all because they never log in.
With the namespace route I have now, my problem is when a "user"
(visitor) is redirected to items_path, because the namespace route
redirect to the admin view instead user view... (unless I change the
order in routes.rb, but if I do that, when the admin is redirected to
items_path the route used is map.resources :items)
Perhaps this is not the best way for doing this... Any suggestions?
PD: I would take a look to Authlogic for next projects