我有模型用户包含列角色。如何用角色替换用户模型的路由
class CreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :address
t.integer :role
t.timestamps
end
end
end
作用店如果User.role = 1,作用是托运人User.role = 0
的routes.rb
resources :users
和URL的行动显示(配置文件):http://localhost:3000/users/1
我想改变它:角色。例如: http://localhost:3000/shops/1(如果User.role = 1) 或.../shippers/1(如果User.role = 0)。
我不知道该怎么做。帮帮我,谢谢!
[Rails Routes based on condition]的可能重复(http://stackoverflow.com/questions/11230130/rails-routes-based-on-condition) – Pavan
http://bjedrocha.com/rails/2015/03/18/role-based-routing-in-rails /请尝试这个我认为这可以帮助你 –