> Should I use existing scaffold-ed controllers and views and make application logic inside (filtering out displaying Edit link is not good idea, users always can "gues" the correct edit URL even I do not show button for edit)?Is there best practice for such common situation?
> thanx a lot for your opinions
>
>
The cancan gem is pretty good at this. You create an ability file where you list what a user can do. At its most basic it would be
class Ability
include CanCan::Ability
def initialize(user)
if user.admin?
can :manage, :all
elsif user.editor?
can :manage, Post, :user_id =>
user.id
end
can read, :all
end
end
(You'd have to repeat the Post bit for other classes)
Then cancan gives you view helpers, for example you could do
<%= if can? :edit, @post %>
# display link to edit here
<% end %>
Last but not least your controllers need to also check that the user is authorized. Cancan provides a default before_filter you can use if you're just using the standard restful actions.
The cancan wiki has loads of examples.
With the above, authorization isn't a reason for splitting up your controllers. However you might still consider splitting your editing interface from the one for the general public - perhaps they will want to see different information, that goes beyond an edit link here and an delete link there. For example perhaps editors would find a concise, table based list of posts useful, whereas users want something prettier. That side of things is probably one you'll need to answer for yourself.
Fred