rolify

How to get devise to work with multiple models or roles? (Preferably with CanCan and rolify)

独自空忆成欢 提交于 2020-01-11 10:43:12
问题 Using devise, what is the best way to have multiple models or roles? Here are the models or roles I need in my app: -Author: can upload content to the site -Customer: pays a monthly fee to access the content A user can be both an Author and a Customer. I think they can share the same login form because they will both log in with their email address. I have tried using CanCan and rolify, but couldn't figure out how to add different roles during registration. When a user registers as an Author,

Fixtures with polymorphic association not working

孤者浪人 提交于 2020-01-06 06:45:22
问题 I'm trying to implement the Rolify gem but have trouble adding fixtures with a scope for it. The last line of the (model) test below fails because currently the moderator role seems to be given to @user globally instead of only for organization one. The fixtures below aren't using resource_id and resource_type , which are mentioned in the gem documentation for fixtures, but I'm not sure how to use them. How should I set the scope for the moderator role to only organization one? roles.yml

Rails 4 - Rolify — setting scoped roles

强颜欢笑 提交于 2019-12-25 18:06:37
问题 I am trying to setup roles on my app. I have models called user, profile, organisation and roles. The associations are: User class User < ActiveRecord::Base rolify strict: true attr_accessor :current_role Profile belongs_to :user belongs_to :organisation Organisation belongs_to :owner, class_name: 'User' has_many :profiles resourcify Roles class Role < ActiveRecord::Base scopify has_and_belongs_to_many :users, join_table: "users_roles" belongs_to :resource, :polymorphic => true validates

Rails 4 - Rolify — setting scoped roles

本小妞迷上赌 提交于 2019-12-25 18:03:03
问题 I am trying to setup roles on my app. I have models called user, profile, organisation and roles. The associations are: User class User < ActiveRecord::Base rolify strict: true attr_accessor :current_role Profile belongs_to :user belongs_to :organisation Organisation belongs_to :owner, class_name: 'User' has_many :profiles resourcify Roles class Role < ActiveRecord::Base scopify has_and_belongs_to_many :users, join_table: "users_roles" belongs_to :resource, :polymorphic => true validates

Adding Role dynamically through Form USing Rolify along with Devise and Cancan

无人久伴 提交于 2019-12-13 02:12:42
问题 I just followed the tutorial "https://github.com/EppO/rolify/wiki/Tutorial" its very nice and working fine. But my question can't we add Role through form with out using Rails console. <div class="field"><%= user_form.label :email %><br /> <%= user_form.email_field :email %></div> <div class="field"><%= user_form.label :password %><br /> <%= user_form.password_field :password %></div> <div class="field"><%= user_form.label :password_confirmation %><br /> <%= user_form.password_field :password

Rails 5, Rolify - removing role from user

吃可爱长大的小学妹 提交于 2019-12-12 12:49:19
问题 I am really struggling to understand something that is fundamental to writing code in rails. I don't know what it is to ask a more fundamental question, but i seem to be having similar problems repeatedly. I have managed to setup rolify in my Rails 5 app. I use rolify to assign roles to users. Now, I'm trying to setup a function to remove roles from users after they are assigned. In my user index, I have; <% user.roles.each do |role| %> <%= role.name.titleize %> <br> <% end %> That shows the

Rolify: Validate roles with complex functionality inside the User model

∥☆過路亽.° 提交于 2019-12-12 04:45:32
问题 I've spent four days trying to achieve this role validation with no success, and I don't know if there is currently any way to do this behaviour with rolify. Here's a simple example of the situation I am having: Suppose I have 3 types of roles: admin developer guest A user can be both an admin and a developer, but cannot be also a guest. A guest cannot be either an admin nor a developer. I want the user to be able to set their roles on user registration, so I need to validate this behaviour

Should each request cost 2 database hits when using Devise+CanCan+Rolify?

有些话、适合烂在心里 提交于 2019-12-12 02:24:29
问题 As much as I can understand, regardless of chosen session store, a Rails app sends one database query for Devise and one database query for Rolify. Here is my related code: <% if !user_signed_in? %> ..login buttons... <% else %> <% unless current_user.has_role? :pro %> <%= link_to "Upgrade!", '#' %> | <% end %> <%= link_to current_user.full_name, edit_user_registration_path %> |<%= link_to "Çıkış", destroy_user_session_path, method: :delete %> <% end %> Those codes causes these SQL queries as

Getting “ArgumentError (wrong number of arguments (given 3, expected 2))” when checking user for roles

╄→尐↘猪︶ㄣ 提交于 2019-12-11 15:05:29
问题 I am using the Rolify Gem on a Rails application. This has worked well until today. I was installing webpacker and stimulus and while doing that ran Bundle Update. This appears to have broken my Rolify functionality. Examined User model carefully and compared to another app where Rolify is still working. Checked Role model, checked database schema to ensure users_roles table is intact. Is there anything in a polymorphic relationship that could cause that Argument error? I apologize if this

How do I restrict the currently logged in user to only see products that belong to them?

痴心易碎 提交于 2019-12-11 15:05:18
问题 If a user is logged in with a specific role - vendor - they should only see items that they have created in their store. They should not be able to see products from other vendors. So I am trying to do this in my authorization (using Devise, CanCan, Rolify). I tried this: user ||= User.new # guest user (not logged in) if user.has_role? :vendor can :dashboard can :manage, [Product, Vendor], :vendor_id => user.id can :view, [Product], :vendor_id => user.id end But....haven't had much luck with