Tag: ruby on rails 3.2

什么是rails中的`stringify_keys’以及如何在出现此错误时解决它

在我的应用程序的部分文件中,我有以下代码片段用于显示用户导航(通过Devise): – ‘delete’ do %> 但我得到一个错误说: – undefined method `stringify_keys’ for “/users/sign_in”:String 现在我的问题是: – 什么是`stringify_keys’一般? 我如何在我的代码中解决这个问题??? 谢谢…

Ruby 1.8.7的分段错误

我正在尝试使用Rails 3.2.0.rc2,但我遇到了一些问题。 当我尝试做rails s我现在得到: /Users/Kyle/.rvm/gems/ruby-1.9.2-p290@skateparks/gems/json-1.6.5/ext/json/ext/json/ext/parser.bundle: [BUG] Segmentation fault ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] [1] 28744 abort rails s 有趣的是我使用1.9.2但错误似乎与1.8.7有关。 我已经做了以下尝试解决这个问题没有成功: rvm gemset empty rvm use 1.9.2@skateparks gem install bundler bundle install

first_or_create通过电子邮件,然后保存嵌套模型

我的两个模型User和Submission如下: class User {:message => “Please enter a valid email address” } validates :email, :uniqueness => { :case_sensitive => false } end class Submission true validates :text, :length => { :minimum => 250 } validates :word_count, :numericality => { :only_integer => true } end 我有一个表格收集这两个模型所需的数据。 用户控制器: def index @user = User.new @user.submissions.build end def create […]

如何使用Fog重命名文件?

我有一个rails 3.2 app。 使用雾来存储S3中的文件。 我想编写一个脚本来重命名已上传的所有文件。 我似乎无法在这个领域找到任何雾文件。 雾有可能吗? 我需要另一颗gem吗?

Rails在Helper中渲染部分

我一直试图在我的控制器内的辅助函数中渲染我的一个部分。 我遇到的第一个问题是帮助程序返回每个循环而不是循环的结果。 为了解决这个问题,我尝试让它返回一个包含循环结果的字符串。 def display_replies(comment) if comment.replies.count > 0 string = “” comment.replies.each do |reply, index| string = string + (render partial: “comment”, locals: {index: index}).to_s.html_safe end string end 在View中调用 当我查看我的视图时,返回并显示的内容是HTML,但它是转义的,因此是纯文本,它看起来像这样: [“\n\n\n\n\nWill Leach\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus adipiscing purus et mi aliquet malesuada. Curabitur porttitor varius turpis eget sollicitudin. Lorem ipsum […]

如何在rails中创建自定义环境作为默认环境?

我通过添加新文件config/environments/staging.rb在我的rails应用程序中created了一个自定义暂存环境,与config/environments/development.rb ,然后添加了数据库配置config/database.yml staging: adapter: sqlite3 database: db/staging.sqlite3 pool: 5 timeout: 5000 现在,我想让我的rails应用程序的default environment而不是开发。如何实现它?

在Rails 3中使用update_columns?

在Rails 3中有没有更短的方法? user.update_column(:attribute1, value1) user.update_column(:attribute2, value2) user.update_column(:attribute3, value3) user.update_column(:attribute4, value4) 我尝试了update_columns但它仅在Rails 4中可用。 谢谢你的帮助。

如何在Ruby on Rails中下载CSV文件?

在我的InvoicesController我有这个: def index @invoices = current_user.invoices respond_to do |format| format.html format.xls format.csv # not working! end end 在我的index.html.erb视图中,我有以下两个下载链接: “xsl”) %> “csv”) %> 模板index.xsl.erb和index.csv.erb也存在。 第一个链接有效,即Excel文件被下载到用户的计算机。 但是,CSV文件在浏览器中呈现而不是下载。 我还必须做些什么才能让用户下载CSV文件? 谢谢你的帮助。

Bundler无法找到gem的兼容版本,更新Rails应用程序

创建一个全新的rails应用程序之后在官方rails博客文章后 ,尝试将应用程序转换为rails 3.2.0.rc2会产生以下结果 Updated Gemfile to depend on rails ~> 3.2.0.rc2 gem ‘rails’, ‘~>3.2.0.rc2’ Updated Gemfile to depend on sass-rails ~> 3.2.3 gem ‘sass-rails’, ‘~> 3.2.3’ $ bundle install Fetching source index for http://rubygems.org/ Bundler could not find compatible versions for gem “activesupport”: In snapshot (Gemfile.lock): activesupport (3.1.1) In Gemfile: rails (~> 3.2.0.rc2) ruby depends […]

覆盖has_many上的ActiveRecord <<运算符:通过关系,接受连接模型的数据

我有三个类:人员,职位和目录。 一个人has_many:目录,:通过=>:位置。 目录has_many:people,:through =>:position。 Person和Directory has_many:position。 除了具有id,person_id和directory_id之外,Position模型还具有一个或多个附加字段(例如,标题)。 我希望能够做的是每次我将一个人添加到Directory.people集合时,将数据添加到连接模型,例如标题字段。 通常的<<运营商不会削减它。 Id est: directory = Directory.last # Let’s assume that retrieves a Directory object person = Person.last # Let’s assume that retrieves a Person object directory.people << person 这会将人员添加到Directory对象的people集合中,但不允许我有机会将数据分配给连接模型。 因此,在对该网站进行了大量研究之后,我发现了另一种方法将Person添加到人员集合中,并将数据添加到链接Person和Directory的位置,id: directory = Directory.last # Let’s assume that retrieves a Directory object person = Person.last # Let’s assume […]