Such a namespace, but different controllers and views in Rails

I have a case where I need to localhost:3000/dashboardpoint to different view / controller combinations depending on the type of user. There are two main types in my application: Subscriberand Publisher.

When Publisherlogs in and goes to /dashboard, I need to show the Publisher toolbar.

When I Subscriberregister and go to /dashboard, I need to show the subscribers panel.

At the moment, the Publisher control panel is called Dashboard, and the Subscriber control panel is called Profile. Seems a little dirty to me.

Question. What is the best way to call the right controller, load the right data and display the correct template / layout based on a specific user?

+3
source share
1 answer

I would consider something like the following pseudo code to get you started.

Controller:

app/controllers/dashboard_controller.rb

class Dashboard < ApplicationController

def index      
  render, :user_type => current_user.user_type
end

View: (Use the helper to change what will be displayed).

views/dashboards/index.html.erb

# display the content

Helper.

helpers/dashboard_helper.rb
module DashboardHelper(user_type)
if user_type == 'publisher'
  #set content / variables for publisher
elsif user_type == 'Subscriber'
  #set content / variables for subscriber
else
  set content/variables to default.
end
+2
source

All Articles