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 3631160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:21:43+00:00 2026-05-19T00:21:43+00:00

I am using devise in my rails application and I have two different resource

  • 0

I am using devise in my rails application and I have two different resource types, like users and companies.

I would like to reuse some code in views, so inspite of writing

if user_logged_in?
   current_user.name 
else  
   current_company.name

I would like to do this the way devise does:

resource.name

Is this possible?

  • 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-19T00:21:43+00:00Added an answer on May 19, 2026 at 12:21 am

    I’m not sure exactly what you mean by “the way devise does”, but you could make an application helper like apnea.diving.deep suggested. Just put this in app/helpers/application_helper.rb (you might want to put it in a different file):

    module ApplicationHelper
      def resource_name
        if user_logged_in?
          current_user.name
        else
          current_company.name
        end
      end
    end
    

    You can now use resource_name in your views.

    (Also, just FYI, the short code snippet you wrote (if user_logged_in?... will fail, as “if”s needs to end with “end”s)

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

Sidebar

Related Questions

I have a Rails 3 application using Devise for authentication. Now I need to
I have a Rails 3 application and it's using Devise for the authentication. I
I'm using rails 2.3.5 and devise 1.0.6. I'm having users confirm account's with email.
I'm using Devise in a Rails application, and I can set session data through
I have installed a gem on my Rails application (devise). After I installed the
I have started using devise for my rails app, however i need to make
I have written a server/client application using sockets in C# for .NET 3.5. I'm
Using the current rails 2 I want users to be able to create an
I am using the googlecharts gem in my rails app for some simple charting.
I am using devise to manage user authentication in my rails app. Devise is

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.