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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:48:57+00:00 2026-05-22T20:48:57+00:00

I’m learning Rails by building a shop application and I’m having a bit of

  • 0

I’m learning Rails by building a shop application and I’m having a bit of trouble with redirects. I have 3 roles in the application:

  • Buyer
  • Seller
  • Administrator

Depending on which type they are logged in as then I would like to redirect to a different page/action but still show the same URL for each (http://…/my-account).

I don’t like having to render partials in the same view, it just seems messy, is there another way to achieve this?

The only way I can think of is to have multiple actions (e.g. buyer, seller, administrator) in the accounts controller but that means the paths will look like http://…/my-account/buyer or http://…/my-account/seller etc.

Many thanks,
Roger

I’ve put my code below:

models/user.rb

class User < ActiveRecord::Base
    def buyer?
        return type == 'buyer'
    end

    def seller?
        return type == 'seller'
    end

    def administrator?
        return type == 'administrator'
    end

    ...

end

controllers/accounts_controller.rb

class AccountsController < ApplicationController  
   def show
   end
end

controllers/user_sessions_controller.rb

class UserSessionsController < ApplicationController
    def new
        @user_session = UserSession.new
    end

    def create
        @user_session = UserSession.new(params[:user_session])

        if @user_session.save
            if session[:return_to].nil?
            # I'm not sure how to handle this part if I want the URL to be the same for each.
                redirect_to(account_path)
            else
                redirect_to(session[:return_to])
            end
        else
            @user_session.errors.clear # Give as little feedback as possible to improve security.
            flash[:notice] = 'We didn\'t recognise the email address or password you entered, please try again.'
            render(:action => :new)
        end
    end

    def destroy
        current_user_session.destroy
        current_basket.destroy
        redirect_to(root_url, :notice => 'Sign out successful!')
    end
end

config/routes.rb

match 'my-account' => 'accounts#show'

Many thanks,
Roger

  • 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-22T20:48:58+00:00Added an answer on May 22, 2026 at 8:48 pm

    In UserSessionsController#create (i.e.: the login method) you could continue to redirect to the account path (assuming that goes to AccountsController#show) and then render different views according to the role. I.e.: something like this:

    class AccountsController < ApplicationController  
      def show
        if current_user.buyer?
          render 'accounts/buyer'
        elsif current_user.seller?
          render 'accounts/seller'
        elsif current_user.administrator?
          render 'accounts/administrator
        end
      end
    end
    

    Better yet, you could do this by convention…

    class AccountsController < ApplicationController  
      def show
        render "accounts/#{current_user.type}"
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.