У меня есть приложение ruby on rails, я определил мое пользовательское разрешение, используя cancancan gem, раньше он работал отлично, недавно я добавил интернационализацию в свое приложение, и с тех пор команда load_and_authorize_resource
вызывает argument error,When assigning attributes, you must pass a hash as an argument.
всякий раз, когдаЯ пытаюсь создать любой новый объект в моем приложении.если я прокомментирую эту строку, она будет работать нормально, или даже если я просто оставлю authorize_resource
, она работает отлично.Я не могу пропустить load_resources
в моем контроллере приложения, так как это приводит к ошибке загрузки других моих моделей в приложение, которые зависят от этого.Я попытался добавить :before_filter
или load_resources
по отдельности на этих моделях, но это тоже не работает.Может кто-нибудь, пожалуйста, помогите мне, как я могу решить эту ошибку.
Вот некоторый фрагмент моего кода.
My application controller:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
around_action :set_current_user, unless: :devise_controller?
before_action :configure_permitted_parameters, if: :devise_controller?
devise_group :user, contains: [:employee, :admin]
before_action :authenticate_user!
before_action :tickets_data, if: :tickets_and_dashboard_controller?
load_and_authorize_resource unless: :devise_controller?
before_action :set_raven_context
after_action :allow_shopify_iframe
before_action :set_locale
include Current
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name,:last_name,:password,:email, :username,:street1, :street2, :state, :zipcode, :city,:phone, :gender, :status,:birthday,:employee_type])
devise_parameter_sanitizer.permit(:sign_up, keys: [:employment_type, :work_group_id, :email, :password, :password_confirmation, :first_name, :last_name, :street1, :street2, :city, :state, :zipcode, :phone, :avatar, :birthday, :gender, :status, :department_id, :work_class_id
])
end
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url
flash[:notice] = exception
end
def default_url_options
{ locale: (current_user.language || Setting.first.language rescue "en")}
end
private
def set_locale
I18n.locale = (current_user.language || Setting.first.language || I18n.default_locale) rescue "en"
end
def allow_shopify_iframe
response.headers['X-Frame-Options'] = 'SAMEORIGIN'
end
def tickets_and_dashboard_controller?
request.path.eql?(tickets_path) || request.path.eql?(root_path)
end
def tickets_data
@open_tickets_count = Ticket.open.count rescue 0
@guest_tickets_count = Ticket.guest_tickets.count rescue 0
@maintenance_tickets_count = Ticket.maintenance_tickets.count rescue 0
@my_tickets = Ticket.where("assignee_id = ?" , current_user.id).order("id desc")
end
def set_current_user
Current.user = current_user
yield
ensure
Current.user = nil
end
def set_raven_context
Raven.user_context(id: session[:current_user_id])
Raven.extra_context(params: params.to_unsafe_h, url: request.url)
end
end
файл способность.rb:
class Ability
include CanCan::Ability
def initialize(user)
if user.type=='Admin'
can :manage, :all
else
# default access
can :manage, Ticket
can :manage, Notification
can :manage, Message
can :manage, Group
can :manage, Conversation
can :manage, Document
can :manage, Skill
can :manage, CaseLog
work_class = WorkClass.find_by_id(user.work_class_id)
if work_class.present?
work_class.pages.each do |page|
case page.name
when "Area"
can :manage, Area
when "Team"
can :manage, Team
when "Work Class"
can :manage, WorkClass
when "Work Group"
can :manage, WorkGroup
when "Room Import"
can :manage, Room
when "Ticket Import"
can :manage, Ticket
when "Ticket Groups"
can :manage, TicketGroup
when "Department"
can :manage, Department
when "Sections"
can :manage, Section
when "Ticketing Rules"
can :manage, Business
can :manage, CreditRule
when "Inspections"
can :manage, Room
can :manage, Inspection
can :manage, InspectionDetail
can :manage, RoomItem
when "Room Grid"
can :manage, Room
can :manage, Inspection
can :manage, InspectionDetail
can :manage, RoomItem
when "Guests"
can :manage, Guest
when "Reservations"
can :manage, Reservation
when "Employees"
can :manage, Employee
can :manage, HrLog
when "Positions"
can :manage, Position
when "Supervisor"
can :manage, EmployeeSupervisor
when "Assignment"
can :manage, Assignment
when "Scheduling"
can :manage, Shift
can :manage, SchedulePattern
when "Inventory"
can :read, Employee
when "Productivity"
can :read, DailyProductivity
when "GRA Manager"
can :manage, GraEmployeeRoom
can [:update], Employee
can [:show], Room
can [:create], CreditRule
when "GRA Portal"
can [:gra_portal,:search,:gra_log_start,:gra_logs],GraEmployeeRoom
when "Daily Sheets"
can [:daily_sheet, :daily_sheet_record_entry, :daily_sheet_date_filter], DailySheet
can :manage, DailySheet
when "Gold Sheets"
can [:gold_sheet, :gold_live_console_entry, :gold_history_entry, :gold_sheet_date_filter], GoldSheet
can :manage, GoldSheet
can :manage, Shift
when "Summary Sheets"
can [:summary_sheet, :summary_sheet_record_entry, :summary_sheet_date_filter, :summary_previous_history_filter], SummarySheet
can :manage, SummarySheet
can :manage, Setting
when "Settings"
can :manage, Setting
when "Schedule Patterns"
can :manage, SchedulePattern
when "OO/OS Dashboard"
can :manage, OutOfOrder
can :manage, Reason
when "Room Items"
can :manage, RoomItem
end
end
end
end
end
end
Спасибо заранее