Tag: 装饰

如何在Rails控制台中包含Draper Decorators?

我想在Rails控制台(https://github.com/drapergem/draper和http://railscasts.com/episodes/286-draper )中看到我的一些Draper装饰器的输出。 为此,我一直在寻找一种方法来包含一个装饰器及其类似于应用程序助手的方法: include ActionView::ApplicationHelper draper装饰器inheritance自ApplicationDecorator,它inheritance自Draper :: Base class ApplicationDecorator < Draper::Base end class MaterialDecorator < ApplicationDecorator decorates :material #methods to decorate your material.. end 我试过include Draper::Base::MaterialDecorator , include ApplicationDecorator::MaterialDecorator ,以及其他一些类似的变种而没有运气。 如何在rails控制台中包含一个装饰器,例如上面的Material Decorator?

在设计中生成有意义的用户名

我正在尝试让我的应用程序自动生成用作名称的用户名。 通常,它们将是用户的名字和姓氏一起添加,但是当已经存在具有相同名字和姓氏的用户时,它将为每个名称增加一个数字。 这是我创建的方法: def full_name first_name + ‘ ‘ + last_name end def user_name t_user_name = first_name.downcase.strip.gsub(‘ ‘, ”).gsub(/[^\w-]/, ”) + last_name.downcase.strip.gsub(‘ ‘, ”).gsub(/[^\w-]/, ”) user_name = t_user_name num = 1 while User.find_by_user_name(user_name).count > 0 num += 1 user_name = “#{t_user_name}#{num}” end end 我目前收到错误: undefined method `find_by_user_name’ 我认为哪个会自动运行? 我也试着在这篇文章中展示的例子: 生成唯一的用户名(omniauth + devise) 但我一直收到错误: Mysql2::Error: Unknown […]

设计错误:未定义的方法`current_sign_in_ip’

我刚刚将Devise安装到我的Rails 4.0.10应用程序中。 我希望用户可以跟踪,但我认为我不需要:current_sign_in_ip和:last_sign_in_ip ,所以我删除了这些属性。 我的迁移: ## Trackable t.integer :sign_in_count, default: 0, null: false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :initial_ip # t.inet :current_sign_in_ip # t.inet :last_sign_in_ip 在我尝试创建第一个用户之后,我收到了以下错误: NoMethodError in Devise::RegistrationsController#create undefined method `current_sign_in_ip’ for # 我不明白为什么甚至调用current_sign_in_ip 。 这是“创建”操作,肯定不包括该方法: def create build_resource(sign_up_params) resource.save yield resource if block_given? if resource.persisted? if resource.active_for_authentication? set_flash_message :notice, :signed_up if is_flashing_format? sign_up(resource_name, […]

设计无法保存用户

将devise_usf_fido gem( https://github.com/Cyber​​Deck/devise-fido-u2f )添加到我的RoR项目后,我无法使用注册页面保存任何创建的设计用户。 任何新用户只会持续一分钟,然后完全消失。 应用控制器 class ApplicationController < ActionController::Base protect_from_forgery with: :exception, prepend: true before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation) } end def authenticate_admin! authenticate_user! redirect_to :root, status: :unauthorized unless current_user.admin? end end 用户模型 class User < ApplicationRecord # Include default devise modules. Others available are: # […]

关于设计可锁定的第n次尝试的自定义消息

我正在寻找一种方法来显示设备可锁定模块中的各种失败尝试的自定义消息。 我发现默认情况下只能通知最后一次尝试: https : //github.com/plataformatec/devise/blob/master/lib/devise/models/lockable.rb#L121 是否有任何优雅的方式来显示第7次和第8次失败尝试的不同警告信息? 你能提出一个吗?

我应该如何在ApplicationController中使用Draper?

我的问题涉及以下开发堆栈: Rails 3.2.1 德雷珀0.14 祖先1.2.5 我想要做的是,将导航提供给我的布局。 所以我在ApplicationController定义了一个beforefilter。 class ApplicationController < ActionController::Base [..] before_filter :current_navigation [..] def current_navigation @n = PublicationDecorator.find(1) end end 正如您在上面的代码清单中看到的那样,我正在使用draper 。 我的PublicationDecorator在ApplicationController不可用。 那么如何让我的所有Publications装饰好? uninitialized constant ApplicationController::PublicationDecorator 我正在使用ancestry gem来实现层次结构。 还有一个问题是,如果我使用的是ancestry ,那么所有物品都会被装饰吗?

使用装饰器,(rails)无法推断ActiveRecord :: Base的装饰器

我在使用装饰器时遇到了麻烦。 我之前从未使用过一个,而且我一直试图使用一个关于我为打破一些电子邮件而做的事情。 然而,因为我之前从未使用过,所以我甚至无法用装饰器做一些非常简单的事情,而且我认为它存在某种forms的设置问题。 我知道除了我的小function之外的所有内容(也就是gemfile等)都是最新的和正确的。 我得到的错误很简单, 无法推断ActiveRecord :: Base的装饰器。 现在我有一个几乎为空的控制器,但在其中,我保存了活动记录部分。 class Admin::ReceivedEmailsController < Admin::ApplicationController 以我的观点为标题, _receive_email.html.haml 我现在所做的一切都是如此: %td= received_email.decorate 我的装饰师 class Admin::ReceivedEmailsDecorator < Admin::ApplicationDecorator def received_email if can? :update, @customer received_email.content else "You need to have the correct admin access to view the email" end end 我觉得这对我来说应该是一件非常重要的事情,但是我不确定它是什么。 有人会知道我错过了什么吗?

如何修复“没有路由匹配”

我是铁轨上的ruby的新手。 我正在研究一个项目并遇到一个表格问题。 我正在使用设计进行身份validation。 我有一个具有管理员和用户角色的用户类。 为用户设计的设备添加/更新方法正常工作。 当我尝试为管理员创建编辑页面时,我遇到了“No route matches [PATCH]”错误。 这是我正在使用的表格 Update Profile {:controller => “admin”, :action => “update” } do |f| %> First Name “form-control”%> Last Name “form-control”%> Email “form-control”%> “btn btn-md btn-success pull-right” %> 这是我的控制器方法 def edit end def update @user = User.find(params[:id]) if request.post? if(@user.update_attributes(params[:first_name, :last_name, :email] )) redirect_to :action => “admin_portal” else […]

将用户重定向到注册

使用before_action :authenticate_user! 检查用户是否登录。但是它会向用户发送login而不是signup 。 试图指导用户signup而不是login不同方式,但他们在成功注册后不会将用户发回原始页面 。 如何发送用户注册并在之后将用户引导回原始页面? 尝试: before_filter :auth_user def auth_user redirect_to new_user_registration_url unless user_signed_in? end 路由文件 Rails.application.routes.draw do devise_for :installs resources :orders resources :products devise_for :users get ‘dashboard’ => ‘pages#dashboard’ get ‘contact’ => ‘pages#contact’ get ‘cart’ => ‘carts#index’ root ‘pages#home’

设计:更新帐户,无需密码确认

我知道在Devise维基页面上他们会解释如何在这里进行操作: https : //github.com/plataformatec/devise/wiki/How-To :-Allow-users-to-edit-their-account-without-providing- 一个密码 但我是Rails的新手(4),我试图做几个小时,但我一直收到“密码不能是空白消息”。任何人都可以解释如何为rails 4做到这一点? 更新:这是我的代码,我使用此代码在名为Registrations的控制器中创建一个文件: class RegistrationsController true redirect_to after_update_path_for(@user) else render “edit” end end end 在我的routes / config中我把它放在: devise_for :users, :controllers => { :omniauth_callbacks => “users/omniauth_callbacks”, :registrations => “registrations” } 我不明白我还有什么要做的……