Tag: ruby

如何在JavaScript中修改Rails脚本中的全局变量?

我在我的Rails控制器中定义了以下变量: $PATH 在JavaScript中我想更改此变量的值: $(“#resetDefaults”).click(function(){ $PATH = ‘3’; //try 1 = ‘3’; // try 2 }); 我已经尝试了上述两种说法,但无法弄清楚如何做到这一点。

本地postrges工作,但似乎无法推动到RAILS_ENV =生产heroku

我的应用程序在localhost:3000上的本地环境中运行得很好。 它从我当地的postgres数据库中提取数据,但我似乎没有更新生产环境。 我的欢迎页面可以在我的https://gcl.herokuapp.com页面上查看,但是当我点击导航链接查看另一个页面时我收到错误,我假设因为该页面调用来自db的数据,它找不到。 我正在做$ rails db:migrate RAILS_ENV=production 我在终端中获得以下输出: (0.2ms) SELECT pg_try_advisory_lock(3666737882978712990); ActiveRecord::SchemaMigration Load (0.6ms) SELECT “schema_migrations”.* FROM “schema_migrations” ActiveRecord::InternalMetadata Load (0.6ms) SELECT “ar_internal_metadata”.* FROM “ar_internal_metadata” WHERE “ar_internal_metadata”.”key” = $1 LIMIT $2 [[“key”, :environment], [“LIMIT”, 1]] (0.2ms) BEGIN SQL (1.9ms) UPDATE “ar_internal_metadata” SET “value” = $1, “updated_at” = $2 WHERE “ar_internal_metadata”.”key” = $3 [[“value”, “production”], [“updated_at”, […]

将查询转换为活动记录

要执行范围查询,我们遵循以下语法 – : oms[:order_items].where(:internal_sla => 3..5) results in this query => #= 3) AND (`internal_sla` 但是如何更改活动记录查询以给我这样的东西=> select internal_sla from order_items where (internal_sla=0) OR (internal_sla=10)

无法找到没有ID的Studio

一切似乎都在正确的地方,但显然不是。 以下是gists描述中包含错误信息的要点。 https://gist.github.com/JRizzle88/7862465 编辑: 以下是跟踪的开头: Started GET “/studios/new” for 127.0.0.1 at 2013-12-08 13:52:41 -0600 Processing by StudiosController#new as HTML Completed 404 Not Found in 1ms ActiveRecord::RecordNotFound – Couldn’t find Studio without an ID: …. ….

rbenv乘客无法加载此类文件 – bundler / setup

我的乘客是作为gem安装的。 Nginx由passenger-install-nginx-module 。 ruby 2.1.1有3个gemsets,rubygemset rails4_1是这个应用程序的正确。 其他post显示类似的问题( 1,2,3 ),但没有一个解决我的问题。 [ 2014-09-29 14:29:17.1212 13182/7f32e5938700 Pool2/Implementation.cpp:287 ]: Could not spawn process for application /home/canoe/apps/app1: An error occured while starting up the preloader. Error ID: b57602d4 Error details saved to: /tmp/passenger-error-jcmrkH.html Message from application: cannot load such file — bundler/setup (LoadError) /home/canoe/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require’ /home/canoe/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require’ /home/canoe/.rbenv/versions/2.1.1/gemsets/rails4_1/gems/passenger-4.0.52/lib/phusion_passenger/loader_shared_helpers.rb:263:in `block in […]

当我动态生成复选框时,我无法使用javascript访问复选框的键

我在html.erb中创建了一个复选框,如下所示: 我创建了javascript来设置一个或另一个: $(‘#fenix_fee_charged’).click(function(){ $(‘#fenix_fee_no_charged’).removeAttr(“checked”); }); $(‘#fenix_fee_no_charged’).click(function(){ $(‘#fenix_fee_charged’).removeAttr(“checked”); }); 当我的检查选项增加时,我决定动态创建复选框: “checkbox inline” %> 当我检查javascript函数时,这不起作用。 我很感激你能给我的任何帮助!

ActiveRecord :: Enum – PG :: InvalidTextRepresentation:ERROR:整数的输入语法无效:

我有一个奇怪的错误,并希望有人能指出我正确的方向。 我有一个名为Organizations的模型,以及一个名为department的属性,请参阅下面的模式摘录: t.integer “department”, default: 0 在我的模型里面已经为这个属性定义了我的枚举,因为我正在使用ActiveRecord :: Enum ,如下所示: enum department: [:conferences, :design_teams, :services, :clubs, :events, :communications] 但是当我查询JobPosting.joins(job: :organization).where(organizations: { department: ‘conferences’ })我收到的错误是: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “conferences” 仅供参考:一个组织有很多乔布斯,乔布斯有很多JobPostings。 但是,当我查询Organization.where(department: ‘conferences’)它可以工作。 任何帮助将不胜感激。

由于错误,无法创建rails应用程序

这就是我正在做的事情 rails new ffffff /usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs’: Could not find railties (>= 0) amongst [activemodel-4.0.0.beta1, activesupport-4.0.0.beta1, atomic-1.0.1, backports-3.1.1, bcrypt-ruby-3.0.1, bson-1.8.3, bson_ext-1.8.3, builder-3.1.4, bundler-1.3.1, chunky_png-1.2.7, coderay-1.0.9, compass-0.12.2, daemons-1.1.9, eventmachine-1.0.3, exceptional-2.0.33, fssm-0.2.10, haml-4.0.0, i18n-0.6.4, jsmin-1.0.1, mail-2.5.3, method_source-0.8.1, mime-types-1.21, minitest-4.6.2, moped-1.4.3, multi_json-1.6.1, nokogiri-1.5.6, origin-1.0.11, polyglot-0.3.3, pony-1.4, pry-0.9.12, pry-nav-0.2.3, rack-1.5.2, rack-mount-0.8.3, rack-protection-1.5.0, rack-test-0.6.2, rack-timeout-0.0.3, rake-10.0.3, rubygems-bundler-1.1.1, rvm-1.11.3.6, sass-3.2.7, shotgun-0.9, sinatra-1.3.5, […]

Rails 2.3.4错误,:rails s &&:bundle不工作?

我有一个朋友,他有一个现有的Rails应用程序,根据environment.rb文件,它似乎是在’2.3.4’中构建的。 他有一些问题,并让我为他调查。 我习惯使用Rails 3.2+。 我下载了他的文件并运行了bundle命令并得到了这个响应: Could not locate Gemfile 然后,我尝试通过运行rails s命令在本地检出站点。 我回来了: Usage: rails new APP_PATH [options] Options: -r, [–ruby=PATH] # Path to the Ruby binary of your choice # Default: /Users/stevenbrooks1111/.rvm/rubies/ruby-1.9.3-p429/bin/ruby -m, [–template=TEMPLATE] # Path to some application template (can be a filesystem path or URL) [–skip-gemfile] # Don’t create a Gemfile -B, [–skip-bundle] […]

使用Ruby中的集合比较两个哈希数组

在此之后我试图比较两个哈希数组: db = [ {:foo => “bar”, :stack => “overflow”, :num => 0.5}, {:foo => “bar”, :stack => “underlow”, :num => 0.5}, {:foo => “bar”, :stack => “overflow”, :num => 0.1} ] csv = [ {:foo => “bar”, :stack => “overflow”, :num => 0.5}, {:foo => “bar”, :stack => “underlow”, :num => 0.1}, ] 我正在尝试使用Ruby […]