如何在Rails控制台中输入Unicode字符?

在使用Rails控制台时,当我输入ä ,会出现\U+FFC3\U+FFA4 。 当然我可以在rails之外输入Unicode字符。 我在Max OS X 10.7.5中使用Ruby 2.0.0p247,Rails 4.0.0。 如何在Rails控制台中输入Unicode字符?

Rails ActiveRecord:Three Table has_many through:associations

我正在尝试构建一个表来处理某个广告系列已使用以下模型关联设置的位置和类别: class Campaign < ActiveRecord::Base has_many :campaign_category_metro_bids, dependent: :destroy has_many :metros, through: :campaign_category_metro_bids has_many :categories, through: :campaign_category_metro_bids end class Metro < ActiveRecord::Base has_many :campaign_category_metro_bids has_many :campaigns, through: :campaign_category_metro_bids has_many :categories, through: :campaign_category_metro_bids end class Category < ActiveRecord::Base has_many :campaign_category_metro_bids has_many :campaigns, through: :campaign_category_metro_bids has_many :metros, through: :campaign_category_metro_bids end class CampaignCategoryMetroBid < ActiveRecord::Base belongs_to :campaign belongs_to […]

黄瓜测试 – 获取RoutingError

怎么了,伙计们。 请帮忙。 当我运行我的黄瓜测试时,我遇到了这个错误: No route matches {:action=>”show”, :controller=>”accounts”} (ActionController::RoutingError) ./features/support/paths.rb:40:in `path_to’ 耙路线显示: account GET /accounts/:id(.:format) {:action=>”show”, :controller=>”accounts”} cucumber_test.feature Scenario: Given… And… Then i should be on Show page function/支持/ paths.rb when /^Show page$/ account_path @account 的routes.rb Myapp::Application.routes.draw do resources :accounts

安装ffi ruby​​ gem时无法找到ffi.h

Ruby版本2.2.4p230 RubyGem版本2.7.2 安装了Ruby-devel和lib64ffi-devel。 使用64位OpenMandriva 3.0,urpmi和rpmdrake。 目标:安装指南针,但首先需要gemffi。 在过去的两天里,我一直在努力搜索互联网,我很难过……我不可能安装早期版本的ruby,因为它依赖于较旧的ncurses。 我觉得替换ncurses会打开一jar令人讨厌的蠕虫。 但是……我也完全接受罗盘替代方案,其中config.rb项目文件可以以某种方式移植/复制,因此罗盘和其他sass编译器都可以运行。 (这是为了工作,我们不会很快改变sass建设者)。 /usr/share/gems/gems/ffi-1.9.18/ext/ffi_c完全存在,该目录中有一个ffi.c文件,但在附近找不到任何ffi.h文件。 在绝望的时刻,我触摸了该目录中的ffi.h,当我运行gem install时将其删除。 ;)我会尝试取一个别人的libs副本,看看是否有效。 基本上任何方法都可以在不破坏我的其他包的情况下实现这一点。 我不会用ruby做任何其他事情,只需指南针。 这是输出: # sudo gem install ffi Building native extensions. This could take a while… ERROR: Error installing ffi: ERROR: Failed to build gem native extension. current directory: /usr/share/gems/gems/ffi-1.9.18/ext/ffi_c /usr/bin/ruby -r ./siteconf20171110-17988-1lodsok.rb extconf.rb checking for ffi.h… *** extconf.rb failed *** […]

Rails是否提供默认的会话超时持续时间? 如果是,它在哪里指定?

我已经知道如何在rails app中设置到期时间,这在网上已经很好地记录了。 但我想知道的是在rails中会话到期的默认持续时间是什么,如果有,在哪里可以找到它?

Ruby roo LoadError:无法加载此类文件 – 电子表格/注释

尝试加载xls文件并获取此错误。 有控制台日志: irb(main):001:0> require ‘roo’ => true irb(main):002:0> a = Roo::Excel.new(‘/home/a.xls’) LoadError: cannot load such file — spreadsheet/note from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’ from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’ from /var/lib/gems/1.9.1/gems/spreadsheet-0.9.2/lib/spreadsheet/excel/reader.rb:5:in `’ from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’ from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’ from /var/lib/gems/1.9.1/gems/spreadsheet-0.9.2/lib/spreadsheet.rb:28:in `’ from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’ from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require’ from /var/lib/gems/1.9.1/gems/roo-1.12.2/lib/roo/excel.rb:1:in `’ from (irb):2 from /usr/bin/irb:12:in `’ 请帮忙解决这个问题 此外,当我尝试需要电子表格时,我得到相同的错误 require ‘spreadsheet’ 但是这个模块是安装的 […]

Rails 2.3.2试图渲染ERB而不是HAML

Rails突然试图渲染ERB而不是Haml,我无法弄清楚原因。 我创建了新的rails项目,重新安装了Haml,并重新安装了Rails。 这正是我在制作应用程序时所采取的步骤(Rails 2.3.2): rails> rails test rails> cd test rails\test> haml –rails . rails\test> ruby script\generate model user email:string password:string rails\test> ruby script\generate controller users index rails\test> rake db:migrate 这是UsersController的样子: class UsersController < ApplicationController def index @users = User.all end end 我的路线: ActionController::Routing::Routes.draw do |map| map.resources :users end 我现在创建views \ users \ index.html.haml : […]

Rails3 omniauth google身份validation返回用户身份

我的Omniauth集成适用于本地开发,但谷歌在登台时失败。 require ‘omniauth/openid’ require ‘openid/store/memcache’ Rails.application.config.middleware.use OmniAuth::Builder do OmniAuth.config.full_host = “http://xx.xx.xxx/” # dedicated openid provider :open_id, OpenID::Store::Memcache.new(Dalli::Client.new), :name => ‘google’, :identifier => ‘https://www.google.com/accounts/o8/id’ end 我收到此错误消息: 开始GET“/ auth / failure?message = invalid_credentials”for 58.71.19.178 at 2011-12-01 02:22:20 +0000由ErrorsController处理#routing as HTML参数:{“message”=>“invalid_credentials”,“a “=>”auth / failure“}渲染公共/ 404.html(0.1ms)已完成404未在1ms内找到(视图:0.6ms | ActiveRecord:0.0ms) 我的OmniAuth.config.full_host中的ip in for也不一样可能导致问题?

如何在Ruby on Rails中为自己的rake任务使用自定义日志?

我有一个rake任务调用这样的函数: namespace :blah do task :hello_world => :environment do logger.info(“Hello World”) helloworld2 end end def helloworld2 logger.info(“Hello Again, World”) end 我希望日志输出到自定义日志,我真的不希望每次进行函数调用时都要传递日志引用。 我发现这个地方(再也找不到了): def logger @@logger ||= Logger.new(“#{RAILS_HOME}/log/blah.log”) end 但是这对我不起作用,我不确定它甚至做了什么,因为我很久以前就抓住了代码并且直到现在才使用它。 我无法在google上搜索@@(尝试+“@@”rails)来查看它的作用。 对这个问题的任何帮助都会很棒。 我希望快速解决方案而不必安装gem或插件(除非有一个非常好的理由。 谢谢!

状态机,模型validation和RSpec

这是我当前的类定义和规范: class Event :not_started do event :game_started do transition :not_started => :in_progress end event :game_ended do transition :in_progress => :final end event :game_postponed do transition [:not_started, :in_progress] => :postponed end state :not_started, :in_progress, :postponed do validate :end_time_before_final end end def end_time_before_final return if end_time.blank? errors.add :end_time, “must be nil until event is final” if end_time.present? […]