in my application, I have a User model. Each user can have several addresses (email addresses) that are defined in the Address model:
Class User < ActiveRecord::Base has_many :addresses def is_authorized(op)
Inside the AddressController class, the current registered user is available in the instance variable "@user". The controller prevents ordinary users from editing, deleting, viewing, etc. Addresses that do not belong to them, but it allows the administrative user to edit them. The AddressController class can query for the AddressModel if the user who is currently logged on is a regular or superuser.
All this works great, and the database updates are performed as expected, however I would really like to have different HTML views depending on the mode of operation. I can only think of two ways to achieve this:
- Make the operation mode (normal / privileged) known in the AddressController class (using an instance variable, for example @privileged), and use the "if" operator in the view.
- Use something like "after_filter" in the address controller to display a different layout.
If you can display the results of one controller in two completely different layouts, depending on the mode of operation, what is a good way to achieve this?
Thanks in advance Stefan
ruby-on-rails actionview actioncontroller
cite
source share