Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 330491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:41:11+00:00 2026-05-12T09:41:11+00:00

in my application, I have a User model. Each user can have multiple (email)

  • 0

in my application, I have a “User” model. Each user can have multiple (email) addresses which are defined in the model “Address”:

Class User < ActiveRecord::Base
  has_many :addresses


  def is_authorized(op)
     # returns true or false
  end

  def is_owned_by(user)
     # returns true or false
  end
end

Class Address < ActiveRecord::Base
  belongs_to :user
end

Inside the AddressController class, the currently logged in user is available in the “@user” instance variable. The controller prevents ordinary users from editing, deleting, viewing etc. addresses which don’t belong to them – but he does allow an administrative user to edit those. The AddressController class can ask the AddressModel if the user currently logged in is performing normal or superuser operations.

This all works nicely and database updates are made as expected, however, I’d really like to have different HTML views depending on the mode of operation. I can only think of two ways to achieve that:

  1. Make the mode of operation (normal/privileged) known in the AddressController class (using an instance variable, e.g. @privileged) and use an “if” statement in the view.
  2. Use something like an “after_filter” in the address controller to render a different layout.

If it is possible to display the results of executing a single controller in two completely different layouts, depending on it’s mode of operation, what is a good way to achieve that?

Thanks in advance
Stefan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:41:11+00:00Added an answer on May 12, 2026 at 9:41 am

    You can specify which view to use to display the result of an action in the action itself. You can also specify which layout to use too. So, for example:

    def my_action
      if @user.is_authorised(...)
        render :action => 'admin_action', :layout => 'admin'
      else
        render :action => 'non_admin_action', :layout => 'non_admin'
      end
    end
    

    This will render either admin_action.html.erb or non_admin_action.html.erb depending on the returned value from is_authorised. The :layout option is, er, optional and refers a layout in views/layouts. There are various other options the render call which you can find in the documentation for render.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 223k
  • Answers 223k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to upgrade Django to the trunk. Using inlines… May 13, 2026 at 12:36 am
  • Editorial Team
    Editorial Team added an answer Even if you try, it is not possible to return… May 13, 2026 at 12:36 am
  • Editorial Team
    Editorial Team added an answer Try java.sql.Date Hopefully this will help you out with the… May 13, 2026 at 12:36 am

Related Questions

I'm prototyping my first MVC application, it's a simple forum. I've done part of
I have an ASP.NET MVC application where I need to allow to customers configure
My application is storing location data from GPS inputs. When importing a GPX file,
Here is my setup. In my application delegate, I have a property called currentFoo.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.