Tag: ruby

缓存在路轨的俄国玩偶

我听说DHH和其他伟大的37Signal人谈了很多俄罗斯娃娃缓存,我理解它的概念,但我真的不知道如何将它应用到我的代码中。 你会怎么样? 新编辑:如何将gem应用于一段包含大量if语句的代码? “avatar topimg” %> “description”) %> “upload icon-upload” %> “description”) %> “upload icon-star” unless current_user.followees_by_type(“design”).blank? %> “description”) unless current_user.followees_by_type(“design”).blank? %> “invites_count”) unless current_user.current_invites “invite icon-plus “+(“blue” unless current_user.current_invites == 0).to_s unless current_user.current_invites “description”) unless current_user.current_invites “activity_count”) unless activity == 0 %> “upload icon-activity “+(“blue” unless activity == 0).to_s unless activity == 0 %> […]

如何在OSX El Capitan上安装libxml-ruby gem 2.3.2?

我正在尝试安装一个在Ruby 1.8.7-p370上运行的旧项目,并且在运行OS X El Capitan的Mac上依赖于旧版本的libxml-ruby 2.3.2 gem。 问题是,当尝试安装gem时,它不会构建本机扩展。 以下是运行gem install libxml-ruby -v ‘2.3.2’时的完整错误: Building native extensions. This could take a while… ERROR: Error installing libxml-ruby: ERROR: Failed to build gem native extension. /Users/myusername/.rbenv/versions/1.8.7-p370/bin/ruby extconf.rb checking for socket() in -lsocket… no checking for gethostbyname() in -lnsl… no checking for atan() in -lm… no checking for atan() […]

Heroku上的act-as-taggable-on

我一直在我的开发应用程序中使用act-as-taggable-on进行标记,但是当我将它推送到Heroku时,我收到了一个令人讨厌的错误: ActionView::TemplateError (PGError: ERROR: relation “tags” does not exist : SELECT tags.*, taggings.tags_count AS count FROM “tags” JOIN (SELECT taggings.tag_id, COUNT(taggings.tag_id) AS tags_count FROM “taggings” INNER JOIN offers ON offers.id = taggings.taggable_id WHERE (taggings.taggable_type = E’Offer’ AND taggings.context = E’tags’) GROUP BY taggings.tag_id HAVING COUNT(*) > 0 AND COUNT(taggings.tag_id) > 0) AS taggings ON taggings.tag_id […]

在Rails模型中是否应该避免使用任何“受保护”的名称?

我是Rails的新手,我只是想知道你的模型中是否应该避免使用任何受保护的名称? 例如,以下内容是否有效: class CreateModel < ActiveRecord::Migration def change create_table :model do |t| t.string :hash t.integer :count t.timestamps end end end 我意识到可能不是一个属性的好名字,但它是一个纯粹的例子。 编辑:所有答案都很好,但我选择了我接受的答案,因为它包含一个巨大的受保护属性列表的链接。

通过以下方式进行多对多:从Associations :: CollectionProxy到AssociationRelation

通过与客户关系密切的客户关系(通过favorites.rb)我有多对多的关系,我想知道如何将CollectionProxy转换为AssociationRelation,这样我就可以获得与用户最喜欢的所有客户的关系。 或者只是简单地说,如何在AssociationRelation中获取它们 – 不必从CollectionProxy转换。 编辑:我正在寻找的只是一个列出所有客户的关系。 我意识到我的问题不同。 我如何与所有客户建立关系? – 不是与favorite_id,user_id等的关系 – 我想要一个纯粹与客户及其行的关系。 我可以像这样找到CollectionProxy: user = User.last user.favorites # Gives me a CollectionProxy 但是我如何找到最喜欢的客户作为AssociationRelation? 楷模: user.rb: has_many :favorites, :dependent => :destroy has_many :clients, through: ‘favorites’ Client.rb has_many :favorites, :dependent => :destroy has_many :users, through: ‘favorites’ Favorite.rb belongs_to :user belongs_to :client

Ruby on Rails – Hash of Arrays,group by和sum by many columns

我有一个类似的问题,这个主题Ruby on Rails – Hash of Arrays,group by和sum by column name 但是,我的问题是group by和sum by with many columns而不是one。 例如:我的哈希 [ {“idx”=>”1234”, “account”=>”abde”, “money”=>”4.00”, “money1″=>”1.00”, “order”=>”00001”, “order1″=>”1”}, {“idx”=>”1235”, “account”=>”abde”, “money”=>”2.00”, “money1″=>”1.00”, “order”=>”00001”, “order1″=>”1”}, {“idx”=>”1235”, “account”=>”abde”, “money”=>”3.00”, “money1″=>”1.00”, “order”=>”00002”, “order1″=>”2”} ] 结果是这样的 [ {“idx”=>”1234”, “account”=>”abde”, “money”=>”6.00”, “money1″=>”2.00″,”order”=>”00001”, “order1″=>”1”}, {“idx”=>”1234”, “account”=>”abde”, “money”=>”3.00”, “money1″=>”1.00″,”order”=>”00002”, “order1″=>”2”} ] 像这样的group_hashes arr, [“order”,”order1″], [“money”,”money1″] […]

处理rails中的关联为has_many通过…但是两个连接表深

编辑4.在我的解释中的一些东西是不正确的…附件是一个(非常糟糕的图形),显示表格和架构是如何,然后我的主要问题是我有什么提供者通过加入通过provider_location表的组位置ID,组位置保存组,最终保存组名。 这就是我想知道的,构建一个这样的表如何获得组名? 从提供者那里一路走来。 这就像我需要一个has_many贯穿。 (大注:图像中的提供商地址和组地址实际上是提供商位置和组位置) 编辑x 3:谢谢@mrshoco。 它让我更接近,现在它就像我的结构其他东西不太正确….我在运行provider_test_location.rb时遇到此错误 vagrant@precise32:/vagrant/ipanmv2$ rake test test/models/provider_location_tes t.rb Run options: –seed 18117 # Running: E Finished in 0.190900s, 5.2383 runs/s, 5.2383 assertions/s. 1) Error: ProviderLocationTest#test_fetching_a_group_name_for_a_provider: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: provider_ locations.group_id: SELECT groups.group_name FROM “groups” INNER JOIN “provider_ locations” ON “provider_locations”.”group_id” = “groups”.”id” INNER JOIN “provid ers” ON “providers”.”id” […]

图像名称未插入到轨道上的ruby中的数据库中

我有一个问题是将图像名称存储到数据库中。 图像上传到文件夹工作正常,但图像名称不会保存到数据库中 型号代码: class Post directory # create the file path path = File.join(directory,name) # write the file File.open(path, “wb”) { |f| f.write(upload[‘imag’].read)} end end 控制器代码: def create @a=params[:post][:imag].original_filename /* how to pass in this image name into params[:post] */ pos= Post.save(params[:post]) if pos redirect_to :action =>”index” else redirect_to :action =>”posts” end end 有人指导我存档这个。 提前致谢。

安装refinerycms时Rails App“Permission Denied”错误

在尝试安装精炼厂,rails应用程序时,我不断收到以下错误: ESL@new-host-2 ~$ refinerycms /Application/MAMP/htdocs/goodwatching create /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247:in `mkdir’: Permission denied – /Application (Errno::EACCES) from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:247:in `fu_mkdir’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:221:in `block (2 levels) in mkdir_p’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:219:in `reverse_each’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:219:in `block in mkdir_p’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:205:in `each’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:205:in `mkdir_p’ from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/actions/empty_directory.rb:51:in `block in invoke!’ from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/actions/empty_directory.rb:133:in `call’ from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/actions/empty_directory.rb:133:in `invoke_with_conflict_check’ from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/actions/empty_directory.rb:50:in `invoke!’ from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/actions.rb:95:in `action’ from […]

链接需要HTTP资产

我想知道是否可以通过HTTP要求一些资产,例如: /* * This is a manifest file that’ll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You’re free to add […]