在RoR的安装文档中,它提到在Windows上运行Ruby on Rails存在许多限制,在某些情况下,整个库不起作用.
这些限制有多糟糕,我是否总是默认使用Linux来编写/运行RoR,Iron Ruby是否可以解决这些限制或者它们是操作系统本身的核心?
编辑感谢您在Linux上安装和运行的答案,但我真的想了解安装文档中引用的功能限制,以及非工作库 - 我试图找到评论的链接,但它是在我安装msi软件包时,安装中引用了我的想法
编辑 感谢最近对IronRuby的引用,它肯定是一个值得关注的项目,因为它显然是一种.NET语言,如果它符合承诺,它将是非常宝贵的.然而,最终,在我的情况下,我只是咬了一口子并安装了一个Ubuntu服务器.
<偏见>我应该在几年前完成它</ bias>
字符串是
ex="test1, test2, test3, test4, test5"
我用的时候
ex.split(",").first
Run Code Online (Sandbox Code Playgroud)
它返回
"test1"
Run Code Online (Sandbox Code Playgroud)
现在我想得到剩下的项目,即`"test2,test3,test4,test5".如果我使用
ex.split(",").last
Run Code Online (Sandbox Code Playgroud)
它只返回
"test5"
Run Code Online (Sandbox Code Playgroud)
如何让所有剩余的项目首先跳过?
有没有办法确定在Rails中运行的Ruby版本(在Web上还是通过script/console)?我安装了Ruby 1.8.6,但我还安装了Ruby Enterprise Edition 1.8.7-20090928,并希望确保它使用正确的安装.
我错过了某个地方的备忘录,我希望你能解释一下这个.
为什么对象的本征类不同self.class?
class Foo
def initialize(symbol)
eigenclass = class << self
self
end
eigenclass.class_eval do
attr_accessor symbol
end
end
end
Run Code Online (Sandbox Code Playgroud)
我的逻辑系列等同于特征类,class.self非常简单:
class << self是一种声明类方法的方法,而不是实例方法.这是捷径def Foo.bar.
因此在对类对象的引用中,返回self应该相同self.class.这是因为,class << self将设置self以Foo.class用于类方法的定义/属性.
我只是困惑吗?或者,这是Ruby元编程的偷偷摸摸的伎俩吗?
我在Ruby Koans的about_symbols.rb中引用了这个测试 https://github.com/edgecase/ruby_koans/blob/master/src/about_symbols.rb#L26
def test_method_names_become_symbols
symbols_as_strings = Symbol.all_symbols.map { |x| x.to_s }
assert_equal true, symbols_as_strings.include?("test_method_names_become_symbols")
end
# THINK ABOUT IT:
#
# Why do we convert the list of symbols to strings and then compare
# against the string value rather than against symbols?
Run Code Online (Sandbox Code Playgroud)
为什么我们必须先将该列表转换为字符串?
我试过这个,但它没有用,似乎是osx.我有一个新的Ubuntu 10.10安装与rvm,rails 3和ruby 1.9.2.我有一个新的rails应用程序,但使用gem或rails会导致以下警告(滞后).
$ rails -v
/home/chance/.rvm/gems/ruby-1.9.2-p180@global/gems/railties-3.0.5/lib/rails/script_rails_loader.rb:11: warning: Insecure world writable dir /home/chance in PATH, mode 040777
/home/chance/.rvm/gems/ruby-1.9.2-p180@global/gems/bundler-1.0.10/lib/bundler/runtime.rb:136: warning: Insecure world writable dir /home/chance in PATH, mode 040777
Rails 3.0.5
Run Code Online (Sandbox Code Playgroud)
$ gem -v
/home/chance/.rvm/rubies/ruby-1.9.2-p180/bin/gem:4: warning: Insecure world writable dir /home/chance in PATH, mode 040777
1.6.2
Run Code Online (Sandbox Code Playgroud)
只是重要的是,这是我的Gemfile:
source 'http://rubygems.org'
gem 'rails'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem "haml"
gem "formtastic"
gem "will_paginate"
gem "devise"
gem …Run Code Online (Sandbox Code Playgroud) 我有一个类似这样的方法:
before_filter :authenticate_rights, :only => [:show]
def authenticate_rights
project = Project.find(params[:id])
redirect_to signin_path unless project.hidden
end
Run Code Online (Sandbox Code Playgroud)
我还想在其他一些控制器中使用此方法,因此我将该方法复制到application_controller中包含的帮助器中.
问题是,在某些控制器中,项目的id不是:id符号,而是fe :project_id(也:id存在a(对于另一个模型)
你会如何解决这个问题?是否可以选择向before_filter操作添加参数(传递右侧参数)?
我知道我可以编写一个Ruby case语句来检查正则表达式的匹配.但是,我想在return语句中使用匹配数据.像这样的半伪代码:
foo = "10/10/2011"
case foo
when /^([0-9][0-9])/
print "the month is #{match[1]}"
else
print "something else"
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢!
请注意:我理解我不会像上面那样对一个简单的情况使用switch语句,但这只是一个例子.实际上,我想要实现的是将许多潜在的正则表达式匹配为可以用各种方式编写的日期,然后相应地使用Ruby的Date类进行解析.
我正在寻找一种方法将参数传递给Chef cookbook,如:
$ vagrant up some_parameter
Run Code Online (Sandbox Code Playgroud)
然后some_parameter在其中一个Chef cookbook中使用.