Tag: ruby on rails

NoMethodError(未定义的方法`’为nil:NilClass):使用jquery-datatables-rails

我一直在尝试按照这些说明对jquery-datatables进行过滤。 在我添加filter之前,它返回数据表所需的json而没有任何问题,但现在我收到上述错误并且无法识别问题。 def index respond_to do |format| format.html format.json do @sbcons = Subcontractor.scoped filters = params[:filter] @sbcons = @sbcons.where(sbcon_type: filters[:type]) unless filters[:type].nil? or filters[:type].blank? @sbcons = @sbcons.where(cscs_card: filters[:cscs]) unless filters[:cscs].nil? or filters[:cscs].blank? @sbcons = @sbcons.where(approved_status: filters[:approved]) unless filters[:approved].nil? or filters[:approved].blank? render json: SubcontractorsDatatable.new(view_context, @sbcons) end end end Subcontractors List <table id="subcontractors" class="table table-condensed table-hover display" […]

Rails 3.0 – 在生产中关闭Compass / SASS – 样式表404

我在Heroku上运行Compass on Rails 3.0并且它的工作正常,但我偶尔会遇到一个问题,其中(某些?)样式表的编译速度与页面的其他部分一样快,因此它们不会被提供(。 css链接导致404,然后页面显示为无样式)。 你们知道如何让Compass在服务器启动时编译所有样式表(在prod中),然后再不再触摸它们吗? 这样它基本上可以预编译所有必要的样式表,并且不存在问题? 或者,在heroku部署之前调用一些脚本将所有样式表编译为公共/样式表,然后完全关闭生产中的Compass会更有意义吗? 谢谢!

如何在Rails中的“编辑”表单中映射关联数据?

这是如何从rails表单中的对象关联提供数据的后续行动? 我想知道,我想使用急切加载来为文章对象的编辑页面提供标签(以及通过关联表格保存的其他属性。在上一个问题中,我被告知我可以使用预先加载预加载该数据的关联。控制器中的IE我扩充.find调用include @article = Article.find(params[:id], :include => [:tags]) 这将是很好的,除了它有两个主要的警告。 首先是它为表格中的字段提供对象。 因此,在此示例中,编辑表单中的:tags字段将填充: [#] 而不是 Wondering 第二个警告是我无法将这些关联提供给自定义字段。 例如,我没有:tags字段,而是有一个:tag_list字段。 在创建文章时,用户在此输入多个标签。 在编辑时,:标签不会按名称映射并放入tag_list字段。 我总是可以将此行添加到控制器: @article.tag_list = @article.tags.map(&:name) 但我正在寻找一个更优雅的解决方案,因为我有很多字段,我必须写这个,这似乎浪费了代码行。 有人可以帮忙吗?

Rails 3拒绝急于加载

我在Rails 3.0.7中工作。 我有一些多对多和一些一对多的关联,无法加载。 我的协会是: Person has_many :friends Person has_many :locations through=> :location_histories Location belongs_to :location_hour Location_hour has_many :locations 在我的控制器中,我有以下内容: @people = Person.includes([[:locations=>:location_hour],:friends]).where(“(location_histories.current = true) AND (people.name LIKE ? OR friends.first_name LIKE ? OR friends.last_name LIKE ? OR (friends.first_name LIKE ? AND friends.last_name LIKE ?))”).limit(10).all 然后在我看来,我有: locations.current是一个定义为: scope :current, lambda { where(“location_histories.current = ?”, true) } […]

Rails 4中的“Factory not registered”错误

我在Rails 4中使用Factory Girl获得了“Factory not registered”错误。这是我在spec / factories / user.rb中为一个简单的Devise用户定义的工厂: FactoryGirl.define do factory :user do email ‘test@example.com’ password ‘foobar’ password_confirmation ‘foobar’ end end 这是spec_helper.rb: ENV[“RAILS_ENV”] ||= ‘test’ require File.expand_path(“../../config/environment”, __FILE__) require ‘rspec/rails’ require ’email_spec’ require ‘rspec/autorun’ require ‘factory_girl’ Dir[Rails.root.join(“spec/support/**/*.rb”)].each { |f| require f } ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) RSpec.configure do |config| config.include(EmailSpec::Helpers) config.include(EmailSpec::Matchers) config.fixture_path = “#{::Rails.root}/spec/fixtures” config.use_transactional_fixtures […]

试图在现有的mysql db上构建rails 3.2 app

我试图弄清楚如何在现有的mysql数据库之上构建一个rails应用程序。 我认为最好的方法就是创建一个与现有数据库布局相同的迁移,但我不太清楚如何做到这一点,然后连接它。 我知道这篇文章使用现有的Mysql数据库构建Ruby on Rails应用程序 但我仍然不确定; 我只是这样做,但我需要的列? 此问题的主要答案是说我应该将我的数据库设为csv然后导入它,是否有人有他们推荐的教程或gem?

编辑表单删除数据库中的记录

我有一个嵌套的表单,可以很好地保存数据库的内容。 唯一的问题是,当我单击编辑时,“grand-child”字段将从数据库中删除,因此我必须重新输入该字段上的所有内容。 正常行为是编辑应存在的先前内容。 我正在使用gem cocoon simple_forms用于我的表单的嵌套表单simple_forms和用于ckeditor编辑的ckeditor 。 这是我单击编辑时的服务器日志:通知: SQL (0.3ms) DELETE FROM “responses” WHERE “responses”.”id” = $1 [[“id”, 53]]每次我点击编辑时都会发生进入考试模型。 另请注意,问题已选中但未删除。 很奇怪。 Started GET “/exams/24/edit” for 127.0.0.1 at 2015-11-09 16:59:40 +0300 Processing by ExamsController#edit as HTML Parameters: {“id”=>”24”} Exam Load (0.8ms) SELECT “exams”.* FROM “exams” WHERE “exams”.”id” = $1 LIMIT 1 [[“id”, 24]] Question Load (0.4ms) […]

Rails Puma用完了Redis连接

我已经在SO上查看了其他类似的问题但是不能很好地将事情拼凑在一起。 我有一个Rails应用程序(在Heroku上),它使用Puma同时具有多个进程和多个线程。 我的应用程序还使用Redis作为辅助数据存储(除了SQL数据库),直接查询Redis(通过connection_pool gem)。 这是我的Puma配置文件: workers Integer(ENV[“WEB_CONCURRENCY”] || 4) threads_count = Integer(ENV[“MAX_THREADS”] || 5) threads threads_count, threads_count preload_app! rackup DefaultRackup port ENV[“PORT”] || 3000 environment ENV[“RACK_ENV”] || “development” on_worker_boot do # Worker specific setup for Rails 4.1+ ActiveRecord::Base.establish_connection redis_connections_per_process = Integer(ENV[“REDIS_CONNS_PER_PROCESS”] || 5) $redis = ConnectionPool.new(size: redis_connections_per_process) do Redis.new(url: ENV[“REDIS_URL”] || “redis://localhost:6379/0”) end end 我的Redis实例的连接限制为20,我发现自己经常超过这个限制,尽管应该是(据我所知)每个进程只有5个连接分布在4个工作进程中。 […]

Ubuntu虚拟环境上的自动测试通知

我无法让Rails自动测试通知在Engine Yard Vagrant环境中工作。 在Mac上,我通常通过Growl收到通知。 但是,在运行Ubuntu的虚拟环境中不起作用。 我尝试运行Linux通知设置,如libnotify + autotest-notification,但是我收到以下错误: libnotify-Message: Unable to get session bus: /bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed. ** (notify-send:1004): CRITICAL **: dbus_g_proxy_connect_signal: assertion `DBUS_IS_G_PROXY (proxy)’ failed ** (notify-send:1004): CRITICAL **: dbus_g_proxy_connect_signal: assertion `DBUS_IS_G_PROXY (proxy)’ failed ** (notify-send:1004): CRITICAL **: dbus_g_proxy_call: assertion `DBUS_IS_G_PROXY (proxy)’ failed 另一条路径是让Growl远程接收通知,但我甚至不知道从哪里开始…… 有什么建议?

我可以使用Paperclip在rails中发表评论吗?

我希望用户能够使用Paperclip支持的图像或gif评论post。 我怎样才能实现这一目标? 它可以与acts_as_commentable一起使用吗?