Tag: ruby on rails

任何人都可以推荐一个用于搜索的gem,它实际上允许我轻松地在轨道上的ruby中过滤我的结果吗?

在指向那个方向后我尝试思考狮身人面像,简单的过滤似乎是不可能的。 我已经用Google搜索了2天的问题并且似乎无法做到这令人震惊,因为这是在网站上搜索时常见的事情。 我只想在搜索表单中添加过滤选项,例如过滤一个或多个组合: 当用户点击浏览页面时,将返回所有网站用户,但每页显示20个结果 过滤选项 在:位置 谁是:性取向 年龄间:年龄范围 和位于:国家 我的搜索页面工作正常,因为我需要的是用户通过电子邮件,用户名或全名查找用户的1个文本字段。 我的浏览页面是一个不同的故事,因为我使用的是一个包含多个文本字段和一个或两个选择字段的表单。 例 有没有一个gem可以轻松地做到这一点并同时表现良好? 或者通过查找方法手动执行此操作是唯一的方法吗? 亲切的问候

如何创建一个表示数据库中的内容的静态类?

我有一张表看起来像: AccountType ID Name Property1 Property2 Property3 在启动时,我想创建一个表示数据库行的类,我可以通过ID和Name引用它们。 我希望这是一个静态表示(它永远不会改变,如果它在极少数情况下,我可以重新启动应用程序)因为我将在我的代码中引用并且不想一直打到数据库。 我在数据库中需要它,因为我还需要将它与其他表连接。 可以这样做吗? 用法: AccountType[1] AccountType[“PRO_PLAN”]

在活动记录中保存字符串时保持前导零

为什么Rails在尝试在活动记录中保存数值时会删除前导零? 即。 self.dps_billing_id = “0000060010123363” self.save! 实际上保存=> 60010123363 该列只是postgres db上的标准字符串字段? t.string “dps_billing_id” 我需要存储前导零,因为我的信用卡网关需要它们,但我也不能简单地在结果上附加几个零,因为数量可以改变。 如何阻止导轨修剪零点?

Rails App与HPQC集成(HP Quality Center)

我想将hp质量中心集成到在linux系统上开发和部署的rails应用程序。 我发现它使用OTA(开放测试架构API)。 但是已经指定它使用OTAclient dll来执行api的活动。 我想知道是否有任何关于这种集成的文档(linux系统上的hpqc + rails)? 是否有可能实现这种整合..任何gem或插件……?

rails中的交叉唯一性模型validation

我有一个模型,我希望列包含不同的ID。 因此,用户可以跟随另一个用户,但不跟随他们自己。 移民 class CreateFollows < ActiveRecord::Migration def change create_table :follows do |t| t.integer :follower_id t.integer :followee_id t.timestamps end end end 模型 class Follow < ActiveRecord::Base belongs_to :follower, class_name: 'User' belongs_to :followee, class_name: 'User' validates :follower_id, uniqueness: { scope: :followee_id } end 但我的测试似乎失败了 测试 it ‘cannot follow itself’ do user = FactoryGirl.create(:user) follow = FactoryGirl.create(:follow, […]

使用批处理脚本在Windows上启动瘦服务器的多个实例

我正在编写一个脚本,以便在Windows中的rails应用程序上自动部署ruby。 除了瘦集群启动之外,我拥有一切自动化function; 事实certificate,Windows不支持守护进程,所以在调用thin时我不能使用-servers命令。 我发布的上一个问题: 在Windows上启动Thin集群 我现在正在寻找另一种方法来以编程方式获取三个实例。 有谁知道我怎么能够做到这一点? 谢谢你的时间!

Rails 5 – ExecJS :: RuntimeError

我的项目工作正常,我正在调整使用chartkick创建的图表并使用ActionCable更新HTML徽章,突然之间我收到此错误: Pages#create_session中的ExecJS :: RuntimeError Showing B:/…/app/views/layouts/application.html.erb where line #7 raised: SyntaxError: [stdin]:14:32: unexpected end of input Extracted source (around line #7): 5 6 7 8 9 10 Application Trace | Framework Trace | Full Trace app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___430303067_44605968′ app/controllers/pages_controller.rb:145:in `render_page’ app/controllers/pages_controller.rb:46:in `create_session’ 我用Google搜索并发现此错误意味着我的系统上的JavaScript运行时存在问题 (我使用的是Windows 10)。 我尝试过的事情: 删除// = require_tree 。 来自application.js – 对我不起作用,因为我的所有JavaScript代码都不再起作用了(我的项目使用ActionCable) 修改C:\ RailsInstaller \ […]

如何分析“未定义方法`attribute_method_matcher’”错误的来源?

我在Rails控制器中创建新类时遇到错误。 我怎么能理解这里发生了什么? 谢谢 Error: NoMethodError in MystudentsController#new undefined method `attribute_method_matcher’ for nil:NilClass Rails.root: E:/Nam 4 HK 1/TT CNPM/workspace/lab2 app/controllers/mystudents_controller.rb:27:in `new’ app/controllers/mystudents_controller.rb:27:in `new’ 这是mystudent_controller.rb文件中的新function: def new @mystudent = Mystudent.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @mystudents } end end

rake gem问题:安装

我在用 Rails 2.3.5,Ruby 1.8.7 运行以下命令后,我收到以下错误。 有任何想法吗? $ rake gem:install $ rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+) $ rake aborted! $ rake gem:install –trace rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+) rake aborted! uninitialized constant ActiveSupport::Dependencies::Mutex /Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in `const_missing’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:55 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require’ /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support.rb:56 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require’ /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require’ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/tasks/misc.rake:18 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/tasks/rails.rb:4:in `load’ […]

如何在两个相互依赖的属性上运行回调函数?

在我的Rails应用程序中,我有一个Invoice模型,其属性为date和due_date 。 为简单起见,我不希望用户手动输入due_date ,而只需输入应添加到date 的天数 。 这就是我设置虚拟属性days_allowed 。 class Invoice < ActiveRecord::Base belongs_to :user before_save :save_date attr_accessor :days_allowed def days_allowed # attribute reader (I need that too!) (due_date – date).to_i end def save_date self.due_date = date + days_allowed.days end end 但是,当用户在表单中选择日期并输入天数(例如10天)时,我得到错误的结果,因为save_date回调引用了days_allowed方法而不是同名属性。 关键问题似乎是我在两个相互依赖的不同属性( date和days_allowed )上使用回调。 谁能告诉我如何解决这个难题? 谢谢你的帮助。