Tag: 设计

管理员更改用户的批准状态 – Rails + Devise + Cancancan

我按照此链接找出如何让管理员批准新用户。 我的User模型上有一个approved属性,它是一个布尔值。 2个问题 – 1)当我以管理员身份登录并通过link_to “Edit”, edit_user_path(user)转到编辑用户时link_to “Edit”, edit_user_path(user)更改已批准的用户 – 该URL用于正确的用户,但更新操作会尝试更新当前的管理员用户。 2)我更希望覆盖所需的当前密码,所以我在Registrations控制器中放置一个方法来执行此操作,但是会出现此错误: 错误:用户的unknown attribute ‘current_password’ for User. 所以它不会覆盖current_password ,也不会更新正确的非管理员用户 – 我哪里错了? class Ability include CanCan::Ability def initialize(user) current_user ||= User.new # guest user (not logged in) if current_user.admin == true can :manage, :all else can :manage, User, id: user.id end end end 路线 Rails.application.routes.draw do […]

未定义的局部变量或#User的方法`confirmed_at’

我正在使用Rails 3.这里可能有重复。 但它没有解决我的问题,也没有解决任何其他问题。 我的迁移如下 class AddConfirmableToDevise true end end 我确实devise :confirmable在User模型中添加了devise :confirmable 。 我的rake db:migrate没有输出。 我的注册页面给出了错误: undefined local variable or method ‘confirmed_at’ for #User 有人有线索吗?

Rails 4设计强参数管理模型

我使用设计制作了用户和管理模型。 我在app / controllers / application_controller.rb文件中使用了强参数 class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_filter :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation, :remember_me) } devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :password, :remember_me) } end […]

在范围自定义窗体中呈现设计错误消息

我必须设计模型, User和Vendor 。 我为供应商生成了视图,并根据我的需要自定义了注册表单。 我需要调整供应商的注册控制器,如下所示: 控制器/销售商/ registrations_controller.rb class Vendors::RegistrationsController < Devise::RegistrationsController skip_before_filter :require_no_authentication def create super end protected def sign_up(resource_name, resource) true end def new super end end 我对Vendor的注册视图如下所示: 视图/销售商/注册/ new.html.erb Sign up resource_name, :url => registration_path(resource_name), :html => {:multiparet => :true} ) do |f| %> true %> 当我尝试渲染页面时,我收到此错误: undefined method `errors’ for nil:NilClass 如何在这种情况下呈现设计错误消息? […]

BCrypt :: Errors :: InvalidSalt:无效的盐设计

当我尝试创建新用户时,我收到此错误,就像这样 >> User.create(:email=>”nandosousafr@gmail.com”, :password => “hello”) BCrypt::Errors::InvalidSalt: invalid salt from /Library/Ruby/Gems/1.8/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:56:in `hash_secret’ from /Library/Ruby/Gems/1.8/gems/bcrypt-ruby-3.0.1/lib/bcrypt.rb:161:in `create’ from /Library/Ruby/Gems/1.8/gems/devise-2.1.2/lib/devise/models/database_authenticatable.rb:110:in `password_digest’ from /Library/Ruby/Gems/1.8/gems/devise-2.1.2/lib/devise/models/database_authenticatable.rb:37:in `password=’ from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:85:in `send’ from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:85:in `assign_attributes’ from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:78:in `each’ from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/attribute_assignment.rb:78:in `assign_attributes’ from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/base.rb:495:in `initialize’ from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `new’ from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.2/lib/active_record/persistence.rb:44:in `create’ from (irb):3 > 的Gemfile require ‘rbconfig’ HOST_OS = RbConfig::CONFIG[‘host_os’] source ‘https://rubygems.org’ gem ‘rails’, […]

Rails:使用可以查看所有用户的设备添加管理员角色

我需要使用设计为我的应用创建一个管理员角色。 我使用设计创建了基本身份validation。 我的应用程序中有一个设计用户模型,但现在我需要一个可以显示编辑并销毁所有用户的管理员。 我试过按照教程,但没有一个帮助。 我正在使用rails 3.0.10和ruby 1.9.2-p290。

Rails设计 – 使用关联模型注册用户

我在这个主题上遇到了一些SO问题,但所有这些问题似乎已经过时或者只是编码错误。 问题:我正在注册用户,作为结帐流程的一部分。 我想在用户注册时收集用户的地址。 我有一个用户模型和一个地址模型。 我似乎无法弄清楚如何正确覆盖Devise的注册控制器以允许额外的参数。 这是我开始的: class User :destroy accepts_nested_attributes_for :addresses end 我也有我的地址模型: class Address < ActiveRecord::Base belongs_to :state belongs_to :user end …在routes.rb中: devise_for :users, controllers: {registrations: ‘registrations’} 最后,我尝试覆盖设计注册的控制器: class RegistrationsController [:address, :address2, :city, :state_id, :zip_code]) } end end

PGError:错误:关系“用户”的列“电子邮件”已存在

我一直在开发一个关于localhost的网站,它很好。 今天早上,我尝试使用命令“git push heroku master”将其推送到heroku,然后“heroku run rake db:migrate”。 当我尝试做第二个时,我有一个错误: Connecting to database specified by DATABASE_URL Migrating to DeviseCreateUsers (20130427200347) Migrating to CreateAuthentications (20130427210108) Migrating to AddTokenToAuth (20130427233400) Migrating to AddNotificationToAuth (20130427234836) Migrating to AddNotifToUser (20130428031013) Migrating to AddDeviseToUsers (20130712103048) == AddDeviseToUsers: migrating =============================================== — change_table(:users) rake aborted! An error has occurred, this and all later […]

Rails 5模型对象未显示所有Devise属性

我正在使用Rails 5 API和设计。 我有一个User模型。 Schema看起来像这样。 create_table “users”, force: :cascade do |t| t.string “email”, default: “”, null: false t.string “encrypted_password”, default: “”, null: false t.string “reset_password_token” t.datetime “reset_password_sent_at” t.datetime “remember_created_at” t.integer “sign_in_count”, default: 0, null: false t.datetime “current_sign_in_at” t.datetime “last_sign_in_at” t.inet “current_sign_in_ip” t.inet “last_sign_in_ip” t.datetime “created_at”, null: false t.datetime “updated_at”, null: false t.index [“email”], name: “index_users_on_email”, […]

我在尝试重置密码时会触发validation错误

我正在使用设计进行身份validation,并且在设置设计后我已经在users表中添加了一些其他字段。 用户只能通过输入电子邮件和密码进行注册,注册后用户可以编辑他的个人资料。 为此,我使用了:on => update。 但是现在当我试图重置密码validation时,触发错误就像名字不能空白而等等等等。 我正在使用设计和使用注册#edit来重置密码。 以下是我的用户模型。 class User { :small => “150×150>”, :medium => “300×300>”, :large => “500×500>” } has_many :blogs, :dependent => :destroy has_many :comments, :dependent => :destroy has_many :followers, :through => :blogs has_many :followings, :class_name => ‘Follower’, :foreign_key => ‘user_id’ has_many :following_blogs, :through => :followings, :source => :blog has_many :blog_followers, :through […]