Tag: ruby on rail

Rails – 单表inheritance与否是申请人/员工关系

我正在开发一个招聘应用程序,用于存储面试人员的记录。 所以我有两个模型 – 申请人和员工,看起来像OO意义上的一个。 即员工早先是申请人。 因此我打算创建一个单表inheritance,如: 申请人<人 员工<人员 申请人的所有领域都在员工中。 员工还有其他几个不在申请人中的领域。 我对这个计划是否正确。 我有另一个类似的场景要处理 – 潜在客户和客户。 更新:随着我越来越多地与STI合作,我开始不喜欢它。

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

我必须设计模型, 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 如何在这种情况下呈现设计错误消息? […]

Rails范围 – 未定义的方法

我有一个名为“event”的模型,其中有一个名为“coming”的范围,它返回将来会发生的事件。 在rails控制台中,每当我输入时 Event.upcoming 它成功返回事件子集。 但是,如果我输入: @events = Event.all @events.upcoming 我得到一个未定义的方法’即将发生’错误。 范围只适用于类而不适用于实例化变量吗? 提前致谢。 Yohann

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’, […]

有没有办法写数据:{turbolinks:false}数十亿次? 轨道的turbolinks值得吗?

turbolinks(5.0.0) Rails 4.2.2 DRY是否会在您的应用data: {turbolinks: false}每个link_to data: {turbolinks: false} ? 或者这是否会破坏Turbolinks的目的,并建议它应该被删除? 如果单击链接,大量的jquery脚本将无法正常工作,除非它包含data: {turbolinks: false } ,脚本将在重新加载页面时正常工作。 我的jquery包含在: $(document).on(‘turbolinks:load’, function () { #something here});

从自定义控制器操作(Rails)注销设计会话

如何从自定义控制器退出设计会话? 我们有内置function吗? 就像我们对user_signed_in?

为什么Devise会将sign_up错误重定向到其他页面?

我创建了新的rails项目,只有一个生成的主页控制器来测试它。 我的设计模型是User ,所以注册页面是http://localhost:3000/users/sign_up 。 如果我触发错误,例如,在没有提供密码的情况下提交表单,我会被重定向到http://localhost:3000/users 。 如何在http://localhost:3000/users/sign_up后继续使用http://localhost:3000/users/sign_up ? 我读了这个问题 , 唯一的答案建议在控制器中使用redirect_to :back 。 问题是我没有超越控制器。 如果覆盖是解决的唯一方法,请解释它应该是什么。 这是我的routes.rb Rails.application.routes.draw do root to: “home#index” get ‘home/index’ devise_for :users end 这是Devise::RegistrationsController的源代码。 我应该如何覆盖new或create来实现我的需求?

将设计密码恢复限制为仅限某些用户

我的应用程序有一个预订系统,允许用户无需密码订阅。 但是尚未完成订阅的恶意用户(=还没有密码)可以按照密码恢复过程设置自己的密码并制止通常的订阅过程。 所以我希望Devise只为经过validation的用户(即完成订阅的用户)提供密码恢复。 如果未经validation的用户正在输入他的电子邮件以尝试获取新密码,我想向他显示“未找到电子邮件”错误,就好像他根本找不到。 我没有找到覆盖Devise的位置来添加这样的范围。 来自Recoverable 这个方法似乎适合但我无法自定义它: # Attempt to find a user by its email. If a record is found, send new # password instructions to it. If user is not found, returns a new user # with an email not found error. # Attributes must contain the user’s email def send_reset_password_instructions(attributes={}) recoverable = […]

如何根据域名更改视图格式

我想知道是否有任何方法可以更改基于域名相同rails应用程序的视图格式。 例如 : www.domain.com => respond_to format.html api.domain.com => respond_to format.xml或format.json 感谢你的帮助

使用SMS Gateway发送/接收短信有什么好处

我正在使用Rails应用程序,并希望通过我的应用程序发送/接收短信。 我看到的两个解决方案是使用SMS网关,并使用与我的Mac配对的手机和我运行的ultraSMS程序,通过手机发送短信。 第二种选择肯定要便宜得多,因为SMS网关对专用号码收取的费用相当多。 据我所知,第二种选择的缺点是1.可靠性:手机和计算机必须始终打开并配对2.可扩展性 SMS网关还有其他主要优势值得付费吗? 还有其他选择吗? 谢谢, 谭