为了在我的heroku生产环境中调试javascript,我需要禁用资产压缩(或者至少压缩javascript).我试着config.assets.compress = false沿config.assets.debug = true,并仍在使用的压缩资产.然后我删除了压缩资产,此时根本没有资产.我补充说config.assets.enabled = false,这没有帮助.我尝试将未压缩的资源复制到各种目录中,包括应用程序root,public和public/assets(后两个使用文件夹"images",javascripts"和"stylesheets"),并将资源直接放入文件夹中三个子文件夹).我最终能够通过更改html来直接引用所有的javascript文件来使javascripts工作.但CSS和图像仍然无法正常工作.
我原以为我原来config.assets.compress = false应该有用.我做错了什么想法?
我发现Model.create!当我一次添加大量记录时,我的陈述需要很长时间才能运行.看看ActiveRecord-Import但是它没有使用哈希数组(这是我拥有的,我认为这很常见).如何提高性能?
我有8个控制器使用will_paginate来分页他们的索引页面.我想覆盖每个"上一个"和"下一个"的默认值,而不必指定相同的选项8次.有没有办法只覆盖默认值一次(可能通过子类化will_paginate).
从根本上说,我想做一个ActiveRecord"update_attributes",同时让ActiveRecord更改为待处理.有没有办法实现这个目标?如果你想知道为什么我会想要这个,请继续阅读.
我有一个由三部分组成的表单:静态部分(彼此独立的文本字段),一组选择(填充条目时增长),以及显示选择对一组依赖对象的影响的部分.更改选择需要往返服务器以确定效果,并且某些选择会影响将来选择的选择.选择被建模为基本模型的has_many关联.例如(注意[]条目指定HTML-SELECTs)
Include [section]
Exclude [subsection]
Exclude [subsection]
Include [section]
Exclude [subsection]
...
Run Code Online (Sandbox Code Playgroud)
我已将表单设置为典型的嵌套属性表单.当选择被更改时,我使用AJAX回发字段,以便获得典型的params哈希值(例如params [:basemodel] [associated_models_attributes] [0] [:field_name]).我想把它变成一个未保存的ActiveRecord,这样我用来生成原始页面部分的部分就可以用来生成JS响应(我正在使用js.erb文件).使用Basemodel.new(params [:basemodel])给出错误
"ActiveRecord::RecordNotFound (Couldn't find AssociatedModel with ID=1 for Basemodel with ID=)
Run Code Online (Sandbox Code Playgroud)
这种情况正在发生(我认为),因为现有关联记录(当前记录中包含非空ID)的ID与从"新"调用生成的空白ID不匹配.
我可以做一些真正的kludgy并创建一些看起来像ActiveRecord的东西(至少足以满足我的偏见)但我必须认为这是一个很常见的问题,它有一个很好的解决方案.
activerecord ruby-on-rails associations update-attributes ruby-on-rails-3
在我的sample_data.rake文件中,我有命令" Diner.create!(...)"导致" uninitialized constant Diner"错误.但是,如果我在Rails控制台中执行相同的"Diner.create!(...)"命令,则表示成功.如果我在sample_data.rake文件中"需要"模型,我会得到错误" ActiveRecord::ConnectionNotEstablished",其中backtrace显示为" active_record/connection_adapters/abstract/connection_pool.rb:318:in retrieve_connection'".这是我的diner.rb文件:
class Diner < ActiveRecord::Base
has_many :redemptions
has_many :surveys, :through => :redemptions
end
Run Code Online (Sandbox Code Playgroud)
并且导致问题的sample_data.rake文件中的代码是:
99.times do |n|
gender = rand(1) == 0 ? "male" : "female"
birthdate = Date.ordinal(DateTime.now.year - 13 - rand(62), rand(364)+1)
Diner.create!(:gender => gender, :birthdate => birthdate)
end
Run Code Online (Sandbox Code Playgroud)
删除上述代码会导致文件成功处理.而且,正如我之前所说,上面的代码在rails控制台中正常工作.
我已成功使用带有RSpec(版本2.0.1)的have_selector.我最近发现了与RSpec 1.3.2相关联的have_tag ... with_tag ...的文档并希望使用它,但是RSpec给了我错误:
undefined method `has_tag?' for #<ActionController::TestResponse:0x105584e80>
Run Code Online (Sandbox Code Playgroud)
在以下几行:
response.should have_tag("div.breadcrumbs select") do
with_tag(:option, :value => @brands.name)
with_tag(:option, :value => @marketsize.name)
end
Run Code Online (Sandbox Code Playgroud)
我尝试用相同的语法替换"have_selector"和"with_selector for"has_tag"和"with_tag",在这种情况下我收到错误消息
undefined method `with_selector' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1::Nested_1:0x105379de8>
Run Code Online (Sandbox Code Playgroud)
我也试过单独留下"with_tag"而代替"have_selector"却没有成功.
我有一个:在品牌Brand上定义的belongs_to关联如下:
belongs_to :loyalty_coupon, :class_name => Coupon, :foreign_key => :loyalty_coupon_id
Run Code Online (Sandbox Code Playgroud)
(还有一个:从Brand到Coupon的has_many关系,但是:belongs_to关系是为了特别注意一个特定的优惠券.两个关联之间的关系名称和链接字段不同,所以不应该有冲突;我只提到它,因为它可能证明是相关的.这种关系表达为has_many :coupons和belongs_to :brand.)
当我显示时Brand.first.loyalty_coupon,我得到"nil"(这没关系,因为我尚未指定一个).当我尝试使用该命令分配loyalty_coupon时Brand.first.loyalty_coupon = Coupon.first,我收到错误消息:
undefined method `match' for #<Class:0x104036d30>
Run Code Online (Sandbox Code Playgroud)
部分追溯如下:
activerecord (3.0.1) lib/active_record/base.rb:1016:in `method_missing'
activerecord (3.0.1) lib/active_record/base.rb:1180:in `compute_type'
activerecord (3.0.1) lib/active_record/reflection.rb:162:in `send'
activerecord (3.0.1) lib/active_record/reflection.rb:162:in `klass'
activerecord (3.0.1) lib/active_record/reflection.rb:173:in `build_association'
Run Code Online (Sandbox Code Playgroud)
如果我这样做同样的错误信息Brand.first.build_loyalty_coupon(因为它做同样的事情,这并不奇怪).我在优惠券模型中没有:has_one,但我也尝试使用:class_name和:foreign_key指定,并在我尝试时得到相同的错误和回溯Coupon.first.brand_loyalty.我想我错过了一些愚蠢的东西,但我看不出它是什么.
我的应用程序控制器中有以下代码:
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
private
def record_not_found
render :text => "404 Not Found", :status => 404
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行它(实际上我运行rake db:migrate)我得到错误uninitialized constant ActiveRecord::RecordNotFound.这似乎太简单了 - 帮助!
安装Rbenv和Ruby 1.9.2和1.8.7,并设置当前项目的1.9.2(它以前使用1.8.7)后,耙将不再运行.运行rake routes给出消息:
Could not find rake-0.8.7 in any of the sources
Run `bundle install` to install missing gems.
Run Code Online (Sandbox Code Playgroud)
跑完后bundle install.
尝试bundle exec rake routes(这是安装Rbenv之前使用的方法)会产生以下错误:
NOTE: Gem.source_index is deprecated, use Specification. It will be removed on or after 2011-11-01.
Gem.source_index called from /Library/Ruby/Gems/1.8/gems/bundler-1.0.9/lib/bundler/shared_helpers.rb:3.
Invalid gemspec in [/Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.8/specifications/jquery-rails-1.0.19.gemspec]: invalid date format in specification: "2011-11-26 00:00:00.000000000Z"
Invalid gemspec in [/Users/jackrg/Documents/Novelty-Stats/vendor/local/ruby/1.8/specifications/tilt-1.3.3.gemspec]: invalid date format in specification: "2011-08-25 00:00:00.000000000Z"
NOTE: Gem.source_index is deprecated, use Specification. It will be …Run Code Online (Sandbox Code Playgroud) activerecord ×3
associations ×2
rake ×2
belongs-to ×1
bulkinsert ×1
bundler ×1
compression ×1
javascript ×1
model ×1
rbenv ×1
rescue ×1
rspec ×1
selector ×1