Tag: 设计

Ruby on Rails,Devise gem。 密码为空时如何删除当前密码?

现在我意识到这个话题已经被覆盖过很多次了。 但是,似乎没有一种解决方案只有在数据库中的密码为空时才能使当前密码字段免除。 我目前在我的用户模型中需要密码,如: def password_required? (authentications.empty? || !password.blank?) && super end 然后我将更新function复制到我的注册控制器中: def update if resource.update_with_password(params[resource_name]) set_flash_message :notice, :updated sign_in resource_name, resource, :bypass => true redirect_to after_update_path_for(resource) else clean_up_passwords(resource) render_with_scope :edit end end 我只是不知道如何在编辑空密码时确保设备不需要密码,我是否还需要从视图中删除current_password字段并执行此操作? (we need your current password to confirm your changes) 任何建议都会很棒,因为我确信我忽略了一些东西,但我仍然是Rails的新手。 谢谢!

如何嵌套devise_invitable路由以邀请用户访问特定项目

问题 我在项目管理网络应用程序上使用devise和devise_invitablegem。 我成功邀请新用户加入网络应用。 但我需要的是邀请新用户参与特定项目,而无法弄清楚如何做到这一点。 我需要将项目ID作为路径的一部分,以便我可以正确连接控制器代码。 上下文 相关routes.rb部分如下: devise_for :users, :controllers => { :invitations => “invitations” } 所以: users/invitation/new作品的新邀请。 我自己的invitations_controller.rb会覆盖默认的InvitationsController 我有:projects作为我正在使用的资源,例如 resources :projects do resources :milestones, :task … etc end (我认为)我希望做出类似这样的工作: users/invitation/projects/4f3423d34323/new

设计gem跳过确认并立即通过电子邮件跳过确认

我正在使用设计gem,在创建用户时我想跳过混乱! 并跳过confimation电子邮件,例如: User.create(:first_name => “vidur”, :last_name => “punj”).confirm!.skip_confirmation! 但它只跳过确认,不会跳过发送确认电子邮件。 任何人都可以给我一个跳过这两个想法的想法。

从JSON创建Devise中的用户

我正在努力将运行Devise的Rails 3.1应用程序与我的iOS应用程序集成以进行用户身份validation。 我希望用户能够从应用程序注册,然后我可以存储这些凭据以便稍后登录。 使用RestKit,我这样做: -(IBAction)registerUser:(id)sender { NSDictionary *params = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: self.email.text, self.password.text, self.confirmPassword.text, nil] forKeys:[NSArray arrayWithObjects: @”email”, @”password”, @”password_confirmation”, nil]]; [[RKClient sharedClient] post:@”/users.json” params:params delegate:self]; } /users.json url转到: user_registration POST /users(.:format) {:action=>”create”, :controller=>”devise/registrations”} (根据rake路由)。 看来post调用接受不同的格式,所以我认为它会接受JSON。 我的post请求被序列化为JSON,并被发送出去。 服务器获取它,这是日志: Started POST “/users.json” for 129.21.84.10 at 2012-01-12 15:33:57 -0500 Processing by Devise::RegistrationsController#create as JSON Parameters: {“password”=>”[FILTERED]”, […]

在Rails中使用Devise gem时如何创建没有电子邮件和密码的用户?

在我的Rails应用程序中,管理员是将用户添加到系统的人员。 如果用户没有电子邮件,则不会为他生成密码,也无法登录。但如果用户有电子邮件,则会生成密码。 但问题是,设计不允许空白密码。 我们该如何解决这个问题?

发送邀请后,Rails设计可邀请的重定向

我得到了设计可用的安装和工作。 试图找出如何在用户发出邀请后重定向用户。 现在它正在将我重定向到根。 我以为你可以在下面的方法中设置你的自定义路径,但它不起作用。 如果有人知道在邀请发送后自定义路径的位置,请提前致谢。 def after_invite_path_for(resource) new_profile_path end

生成唯一的用户名(omniauth + devise)

我有一个带有devise + omniauth用户身份validation的应用程序。 在我的模型中,我的应用中的用户名是唯一的 。 我不想在我的应用程序中重复用户名。 Facebook中的某些用户在其个人资料中没有定义的用户名。 如果用户没有在facebook中定义的用户名,我想生成一个唯一的用户名。 例如,为了生成密码我有这个: :password => Devise.friendly_token[0,20] 如果Facebook用户在Facebook中没有用户名,我怎样才能为我的应用生成唯一的用户名? 谢谢

rails 3.2子域和设计

我有一个应用程序,用户可以登录到他们的公司子域。 我用设计。 此代码将用户从根域重定向到子域。 def after_sign_in_path_for(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope) subdomain_name = current_user.firm.subdomain if current_subdomain.nil? # logout of root domain and login by token to subdomain token = Devise.friendly_token current_user.loginable_token = token current_user.save sign_out(current_user) flash[:notice] = nil home_path = valid_user_url(token, :subdomain => subdomain_name) return home_path else if subdomain_name != current_subdomain.name # user not part of current_subdomain sign_out(current_user) […]

允许匿名/来宾用户“试用”function,而无需在Rails / Devise / CanCan应用程序中注册

我正在使用Devise和CanCan开发一个Rails 3应用程序。 该应用程序允许匿名(未注册)用户访问某些应用程序,并允许注册用户访问其他部分。 应用程序(瑜伽锻炼应用程序)的一个方面是用户可以通过将瑜伽姿势串联起来创建瑜伽序列,然后他们可以在video播放器中播放它们。 我目前已经为注册用户提供了所有function,但是现在希望允许匿名用户能够创建序列并播放它,但要“保存”它(即能够在任何后续会话中再次使用它) ,他们需要注册。 目前,这需要实际创建一个属于用户的Sequence模型实例(简化如下) class Sequence “OrderedAsanaSequence”, :order => ‘position ASC’, :dependent => :destroy has_many :asanas, :through => :ordered_asana_sequences belongs_to :user def status_must_be_private_if_user_nil errors.add(:status, “must be private is user is nil”) if user == nil and status != :private end end 但是,当然,匿名用户没有用户模型。 我有点在Hackces属于用户的东西,但它不是强制性的(user_id可以是nil,如上所示),并且通过CanCan保护编辑的能力: class Ability {snip} # A guest can play with […]

Rails设计:登录后如何访问注册页面?

我是rails的新手,我正在使用“devise”gem进行身份validation。 首先,我通过默认注册页面添加新用户(例如/ users / sign_up) 然后,我通过以下说明向sign_in用户提供“sign_up”页面 在filter之前进行设计,以防止访问“new_user_registration_path”,除非用户已登录 现在,在我尝试打开注册页面登录过程后,它总是指示我到root_path! 我如何访问注册页面? 我的“roots.rb”文件如下: Example::Application.routes.draw do devise_for :users, :controllers => { :registrations => ‘registrations’} resources :companies resources :orders resources :customers root :to => “welcome#index” end 谢谢你们!