Tag: ruby

如何使用jquery-Tokeninput和Acts-as-taggable-on

这是您使用jQuery Tokeninput和ActsAsTaggableOn自动完成的方式 。 在我的情况下,我使用嵌套的forms,但它不重要。 以下所有内容都是有效的代码。 码 产品型号: attr_accessible :tag_list # i am using the regular :tag_list acts_as_taggable_on :tags # Tagging products 产品控制器: #1. Define the tags path #2. Searches ActsAsTaggable::Tag Model look for :name in the created table. #3. it finds the tags.json path and whats on my form. #4. it is detecting the attribute […]

无法让rails-cors在rails应用程序中工作

我想在我的rails应用程序中实现CORS,所以我用Google搜索了rack-cors gem。 我按照README中的说法做了一切,相应地更新了Gemfile并更新了application.rb如下所示: module YourApp class Application :any, :methods => [:get, :post, :options] end end end end 但它没有用。 无论我做了什么,在浏览器控制台中我都会收到消息: XMLHttpRequest cannot load https://somewebsite.com. Origin http://0.0.0.0:3000 is not allowed by Access-Control-Allow-Origin. 在阅读了这篇关于github的博文和问题之后,我意识到中间件堆栈中机架中间件的位置可能很重要。 所以我按照github问题的说法做了: module YourApp class Application :any, :methods => [:get, :post, :options] end end end end 在那之后,当我运行rake middleware rack-cors真的处于堆栈的顶端。 但它仍然只是根本行不通。 我一直得到同样的错误。 任何人,请帮忙。

为什么Nokogiri xpath不像xmlns声明

我正在使用Nokogiri :: XML来解析Amazon SimpleDB的响应。 响应类似于: Foo42 BarXYZ 如果我直接将响应交给Nokogiri,则所有XPath查询(例如doc/”//Item/Attribute[Name=’Foo’]/Value” )都会返回一个空数组。 但是,如果我从SelectResponse标记中删除xmlns属性,它将完美地运行。 是否需要做一些额外的事情来解释名称空间声明? 这种解决方法感觉非常像黑客。

Rails 3.获取Errno :: EACCES权限在生产时上传文件时被拒绝

该应用程序在开发中工作正常,但在生产中,当我尝试使用Carrierwave上传文件时,我得到Errno :: EACCES Permission Denied错误。 我确定它与权限有关。 如何设置允许文件上传的权限? pdf_uploader.rb def store_dir “#{Rails.root}/uploads/#{model.id}” end def cache_dir “#{Rails.root}/tmp/uploads/cache/#{model.id}” end

使用ruby从一些.txt文档中提取所有电子邮件地址

我必须从一些.txt文档中提取所有电子邮件地址。 这些电子邮件可能具有以下格式: a@abc.com {a, b, c}@abc.edu 一些其他格式,包括一些@标志。 我选择ruby作为我的第一语言来编写这个程序,但我不知道如何编写正则表达式。 有人会帮助我吗? 谢谢!

Rails夹具未加载rspec

所以,我正在尝试在rails项目的上下文中学习rspec BDD测试框架。 我遇到的问题是,在我的生活中,我无法在rspec描述中正确加载我的灯具。 免责声明:是的,有比使用固定装置更好的东西。 我正在尝试一次学习一件事,这里(特别是rspec)在我玩相关工具之前,比如工厂女孩,摩卡,自动测试等。因此,我试图让死者变得简单,如果笨重,固定装置工作。 无论如何,这是代码: /test/fixtures/users.yml – # password: “secret” foo: username: foo email: foo@example.com password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f password_salt: bef65e058905c379436d80d1a32e7374b139e7b0 bar: username: bar email: bar@example.com password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f password_salt: bef65e058905c379436d80d1a32e7374b139e7b0 /spec/controllers/pages_controller_spec.rb – require ‘spec/spec_helper’ describe PagesController do integrate_views fixtures :users it “should render index template on index call when logged in” do session[:user_id] = user(:foo).id get […]

如何衡量Ruby对象的大小?

我有Memcache问题,我想知道什么是了解我创建的对象有多大的最佳方法。 我唯一的解决方案是将它们放入Memcache中,以字节显示它们的大小(顺便说一句,我可以自定义Memcache的输出吗?我想要可读的千字节……)。 谢谢, 凯文

在Ruby 1.9.3中安装Mongrel

如何成功安装Mongrel for ruby​​ 1.9.3 这是错误: Building native extensions. This could take a while… ERROR: Error installing mongrel: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb checking for main() in -lc… yes creating Makefile make compiling http11_parser.c compiling http11.c http11.c: In function ‘http_field’: http11.c:70:3: error: format not a string literal and no format arguments [-Werror=format-security] […]

rails 3:如何为现有数据库表生成模型

我已经将我的database.yml配置为指向我现有的mysql数据库 我怎样才能从中生成模型? rails generate model existing_table_name 只提供一个emty模型..

在rails中进行Http基本身份validation

嗨,我来自Grails背景,是Rails的新手。 我希望在rails中进行http基本身份validation。 我有grails中的代码,它执行基本身份validation,如下所示: def authString = “${key}:”.getBytes().encodeBase64().toString() def conn = “http://something.net”.toURL().openConnection() conn.setRequestProperty(“Authorization”, “Basic ${authString}”) 是否可以使用rails完成相同的操作? 提前致谢。