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

  • SEARCH
  • Home
  • 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 9013503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:17:06+00:00 2026-06-16T03:17:06+00:00

My Rails app /index path should show one page to logged in users, an

  • 0

My Rails app /index path should show one page to logged in users, an entirely different page to admin users, and a totally different one for users who aren’t logged in.

So, one controller (HomeController), one action (index), three views.

I can implement this in two ways:

  1. Insert if clauses into views/home/index.html.erb making it do the right thing.
  2. Put the conditional logic into the controller somehow (make the controller find out who the user is) and then render a different layout accordingly, as described under 2.2.12 Finding Layouts in http://guides.rubyonrails.org/layouts_and_rendering.html.

I have a strong feeling the latter solution is the right one. But I’m not sure how to implement it, what with the user controller being a totally different controller. How can my home controller find out who the current user is to decide what view to render?

  • 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-06-16T03:17:08+00:00Added an answer on June 16, 2026 at 3:17 am

    You have access to current_user object in all controllers, to check whether user is logged-in or not. Also we can get user role from the current_user object by

    current_user.role_name

    You can pass this role name to render partial as file name(Keep different files).

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

Sidebar

Related Questions

When trying to access the Reasons Index page NameError in Reasons#index Showing /home/alec/workspace/rails/nwis/app/views/reasons/index.html.erb where
I currently have the following controller method in a Rails app: def index @entries
My rails app allows users to edit a certain json file through the browser.
My rails app crashes as soon as I access a web page. My versions
My rails app talks to a couple different APIs, and I'd like to write
I'm making an app in Ruby on Rails 3.1.3. I have different types of
I've split my rails app into a admin directory and a public directory. The
I have this routes in my app (rails 3.2): godmode_invites GET /godmode/invites(.:format) godmode/invites#index POST
In this rails app: https://github.com/ryanb/govsgo/blob/master/app/views/authentications/index.html.erb There is a form that as 'new_user_path' Where is
I created a routing test rails3 app with one model 'User': rails new routing_test_app

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.