Different set of Views for different user's roles

送分小仙女□ 提交于 2019-12-01 09:26:07

You can do something like in this Railscast Mobile Devices:

in config/initializers/mime_types.rb add:

Mime::Type.register_alias "text/html", :basic 

in app/controllers/application_controller.rb add:

before_filter :check_user_status
private
def check_user_status
  request.format = :basic if current_operator.op_type == 'basic'
end

Now you can just do the following in your controllers:

class SomeController < ApplicationController
  def index
    # …
    respond_to do |format|
      format.html  # index.html.erb
      format.basic # index.basic.erb
    end
  end
end

As you have only two different user's role you can do this

page = (current_operator.op_type =='basic')?  "devices/index_basc.html.erb"  : "index.html.erb"
format.html { render :template => page}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!