我有一个简单的代码表格:
<%= simple_form_for @business, :html => {:class => "form-inline"} do |f| %>
<%= f.association :business_type, :as => :collection_select, :input_html => {:class => "input-small"}, :label => "Type of Business"%>
<%= f.button :submit, :class => "primary pull-left" %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在business type模型中,我有以下内容:first_tier,second_tier,third_tier.
我希望select允许用户选择business type模型中的所有选项,除了first_tier选项外,但无法使其工作.
谢谢.
我想用正则表达式(使用Ruby)将一些文本拆分成句子.它不需要准确,因此可以忽略诸如"华盛顿特区"之类的情况.
但是我要求如果引用句子(通过单引号或双引号),则应该忽略它.
说我有以下文字:
一句话."哇." 爱丽丝说.塞内斯三.
它应分为三句话:
一句话.
"哇." 爱丽丝说.
句子三.
目前我有content.scan(/[^\.!\?\n]*[\.!\?\n]/),但我的报价有问题.
更新:
目前的答案可能会遇到一些性能问题.请尝试以下方法:
'Alice stood besides the table. She looked towards the rabbit, "Wait! Stop!", said Alice'.scan(regexp)
Run Code Online (Sandbox Code Playgroud)
如果有人能弄清楚如何避免它会很好.谢谢!
我希望像这样有SEO优化的网址
http://example.com/sites/1-blau.de/plans
Run Code Online (Sandbox Code Playgroud)
但路径中的点导致Rails陷入困境.如何将点转换为百分比表示形式,以便它可以工作?
我的路线:
resources :sites, only: [] do
resources :plans, only: [:index, :show] do
end
end
Run Code Online (Sandbox Code Playgroud)
我尝试过URI.escape和CGI.escape,但都没有用.
URI.escape('a.b')=> "a.b"
CGI.escape('a.b')=> "a.b"
Run Code Online (Sandbox Code Playgroud)
我以为我想要什么
Foo.escape('a.b')=> "a%2Eb"
Run Code Online (Sandbox Code Playgroud) 以前,我使用gem提供了一个控制器,该控制器用于接受外部服务以将一些数据发布到我们的应用程序中。但是在Rails 5.2中,它停止了工作。当端点被触发时,它将引发ActionController::InvalidAuthenticityToken错误。
嗨,我并尝试rspec模拟以下类:
class Person
def initialize(personid)
Rails.logger.debug "Creating person with id #{personid}"
end
end
Run Code Online (Sandbox Code Playgroud)
使用这个:
require 'spec_helper'
describe Person do
describe "#initialize" do
let(:rails_mock) { double("Rails").as_null_object }
let(:logger_mock) { double("Rails.logger").as_null_object }
it "logs a message" do
rails_mock.stub(:logger).and_return(logger_mock)
logger_mock.should_receive(:debug)
Person.new "dummy"
end
end
end
Run Code Online (Sandbox Code Playgroud)
并得到此消息:
RSpec :: Mocks :: MockExpectationError:(双倍“ Rails.logger”)。debug(任何参数)
预期:1次
收到:0次
任何帮助将是巨大的!
我有这个大型XML文件.有一个字段,我想按空格分割字段.
所以我执行以下操作将分割数据保存到&b:
components = a.split(' ')
a = components[0]
b = components[1]
Run Code Online (Sandbox Code Playgroud)
但是有些是正确分割的,但有些则不正确(当它们都包含空格时).例如,当我尝试拆分时,'Maria Canada'它不会按空格分割.
我不知道为什么.如果我在Vim中打开文件并复制那些特定的错误文本,我可以在Ruby交互式shell中正确拆分它们:
'Maria (Canada)'.split(' ')
=> ["Maria","(Canada)"]
Run Code Online (Sandbox Code Playgroud)
UPDATE
好的原因是NBSP.我通过引发错误打印出那些没有在控制台中分开的行.我复制了文本并粘贴在irb中.这些复制的文本也不能在irb中拆分,也不能剥离该空间.
>> ' '.strip
=> " "
Run Code Online (Sandbox Code Playgroud)
然后我运行ord并发现该空间是一个NBSP字符(其代码为160):
>> ' '.ord
=> 160
Run Code Online (Sandbox Code Playgroud)
因此xml文件包含空格和NBSP字符.我认为Vim自动将NBSP转换为空格,这就是为什么当我尝试从vim复制它时,它不再是NBSP了.
现在我只需要弄清楚如何处理NBSP.
由于Float#roundRuby 1.8.6中的一个错误,我被迫升级到1.9.3,而男孩则非常糟糕.安装后,irb无法正常工作,抱怨缺乏psych.所以我尝试安装gem,但它很生气,libyaml不存在,所以我安装了.不确定如果他们如此重要,他们为什么不被包括在内.
现在当我使用require 'Location.rb'(必须指定我实际上想要查看当前文件夹...使用$LOAD_PATH)后,我收到此错误:
LoadError: cannot load such file -- crack/xml
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/ap-0.1.1/lib/ap.rb:2:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from /Users/tyre77/Dropbox/Aurora/GMap.rb:4:in `<top (required)>'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from (irb):3
from /usr/local/bin/irb:12:in `<main>'
Run Code Online (Sandbox Code Playgroud)
这是什么意思?另外,当我执行时ruby -v,它将我的版本列为1.9.3p0,但这在1.9.1中是不是很有用?我想要的只是我的回归和工作!
请帮助实现ssl
rails版本 - 3.2.8
我编辑了以下文件:
# Gemfile
gem 'rack-ssl'
# config/application.rb
require 'rack/ssl'
config.middleware.use Rack::SSL
Run Code Online (Sandbox Code Playgroud)
我也试过用
# config/application.rb
config.force_ssl = true
Run Code Online (Sandbox Code Playgroud)
但它表明
SSL connection error
Run Code Online (Sandbox Code Playgroud)
当我访问mysite:3000 /
但如果转到https:mysite,它会显示正常页面
请帮忙,
谢谢,
d
我想将Sidekiq gem添加的delay方法重命名为。此扩展方法已添加到Ruby中的所有类。如何使用Ruby元编程来做到这一点?sidekiq_delay
我想这样做,因此Sidekiq delay不会覆盖Delay Job的delay方法。
资产过滤掉,将不送达:添加
Rails.application.config.assets.precompile += %w( login.js )到config/initializers/assets.rb并重新启动服务器
当我尝试运行我的应用程序时,我发现上述错误.
<% content_for :javascripts do %>
<%= javascript_include_tag 'login' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我已将所有js文件放入assets/javascripts,但仍然出现上述错误.