我是一名初学者,我从https://github.com/rubytaiwan/jobs.ruby.tw获得了一个演示.
但是当我尝试运行这个演示时,我收到了一个错误.
我跟着跑
bundle
Run Code Online (Sandbox Code Playgroud)
我收到了错误
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)
但我可以肯定我已经安装了mysql2
而且Gemfile是
source 'https://rubygems.org'
ruby "1.9.3"
gem 'rails', '~> 3.2.12'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git' …Run Code Online (Sandbox Code Playgroud) 我的Rails是3.2.1.4,Ruby是1.9.3p448.
我安装时遇到错误ruby-debug:
Building native extensions. This could take a while...
ERROR: Error installing ruby-debug:
ERROR: Failed to build gem native extension.
/home/hxh/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb
Can't handle 1.9.x yet
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/hxh/.rvm/rubies/ruby-1.9.3-p448/bin/ruby
Gem files …Run Code Online (Sandbox Code Playgroud) 我先执行命令:
sudo service mongodb restart
Run Code Online (Sandbox Code Playgroud)
我收到提示:
stop: Unknown instance:
mongodb start/running, process 3175
Run Code Online (Sandbox Code Playgroud)
然后,我执行命令:
mongo
Run Code Online (Sandbox Code Playgroud)
我收到错误:
MongoDB shell version: 2.4.6
connecting to: test
Tue Oct 8 19:48:08.961 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
Run Code Online (Sandbox Code Playgroud)
我不知道我是怎么得到这个错误的.
如果我有一个meet模型在Rails中,现在我想获得昨天的记录,我该怎么办?
Meet.where(:created_at=> ) # what should I write here?
Run Code Online (Sandbox Code Playgroud)
或者ActiveRecord附带了一些过滤昨天记录的方法?
我想在 Rails 助手中包含一个模块(也是一个模块)。
帮助者是:
module SportHelper
.....
end
Run Code Online (Sandbox Code Playgroud)
该模块是:
module Formula
def say()
....
end
end
Run Code Online (Sandbox Code Playgroud)
say现在,我想使用中的方法SportHelper。我应该怎么办?
如果我这样写:
module SportHelper
def speak1()
require 'formula'
extend Formula
say()
end
def speak2()
require 'formula'
extend Formula
say()
end
end
Run Code Online (Sandbox Code Playgroud)
这会起作用,但我不想这样做,我只想在帮助器模块上添加方法,而不是每个方法。
我需要将远程文件保存到云存储服务器,所以我必须将此文件读取到文件流,我发现这篇文章: 从本地文件或 url 打开 IO 流 答案是:
require 'open-uri'
file_contents = open('local-file.txt') { |f| f.read }
web_contents = open('http://www.stackoverflow.com') {|f| f.read }
Run Code Online (Sandbox Code Playgroud)
但这web_contents是不对的。然后我将此操作与自定义本地文件上传进行比较,格式是什么ASCII-8BIT,格式不一样。所以如何从远程文件中获取正确的流。
Tempfile 我想知道和之间的区别File。
我找到 :
require 'open-uri'
open('c:/boot.ini'){|file|
puts file.class #File
}
open('http://coderlee.cnblogs.com'){|file|
puts file.class #Tempfile
}
Run Code Online (Sandbox Code Playgroud)
当我将流保存到远程存储服务器时,会Tempfile导致错误,似乎是编码的原因,不是ASCII-8BIT为什么?
在我的Rails应用程序中,我运行以下操作:
def test
data={:student=>{:name=>'hxh',:age=>12}}
render xml: data
end
Run Code Online (Sandbox Code Playgroud)
我有
<hash slick-uniqueid="3">
<div>
<a id="slick_uniqueid"/>
</div>
<student>
<name>hxh</name>
<age type="integer">12</age>
</student>
</hash>
Run Code Online (Sandbox Code Playgroud)
但我只想要:
<student>
<name>hxh</name>
<age type="integer">12</age>
</student>
Run Code Online (Sandbox Code Playgroud)
我该怎么认识到这一点?