可能重复/更近期/不太清楚的问题
使用Git从先前的提交中分支
我有一个Git分支,jzbranch并且有一个旧的提交ID : a9c146a09505837ec03b.
如何justin根据上面列出的信息创建新分支?
我有以下哈希 {"CA"=>2, "MI"=>1, "NY"=>1}
如何使用ruby返回最大键值对?我希望它返回"CA"
我正在尝试对序列化列进行简单查询,你是如何做到这一点的?
serialize :mycode, Array
1.9.3p125 :026 > MyModel.find(104).mycode
MyModel Load (0.6ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`id` = 104 LIMIT 1
=> [43565, 43402]
1.9.3p125 :027 > MyModel.find_all_by_mycode("[43402]")
MyModel Load (0.7ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`mycode` = '[43402]'
=> []
1.9.3p125 :028 > MyModel.find_all_by_mycode(43402)
MyModel Load (1.2ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`mycode` = 43402
=> []
1.9.3p125 :029 > MyModel.find_all_by_mycode([43565, 43402])
MyModel Load (1.1ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`mycode` IN (43565, 43402)
=> []
Run Code Online (Sandbox Code Playgroud) 我正在尝试将数组传递给hidden_field.
以下用户有3个角色[2,4,5]
>> u = User.find_by_login("lesa")
=> #<User id: 5, login: "lesa", email: "lesa.beaupry@gmail.com", crypted_password: "0f2776e68f1054a2678ad69a3b28e35ad9f42078", salt: "f02ef9e00d16f1b9f82dfcc488fdf96bf5aab4a8", created_at: "2009-12-29 15:15:51", updated_at: "2010-01-06 06:27:16", remember_token: nil, remember_token_expires_at: nil>
>> u.roles.map(&:id)
=> [2, 4, 5]
Run Code Online (Sandbox Code Playgroud)
用户/ edit.html.erb
<% form_for @user do |f| -%>
<%= f.hidden_field :role_ids, :value => @user.roles.map(&:id) %>
Run Code Online (Sandbox Code Playgroud)
当我提交我的编辑表单时,我收到一个错误:UsersController中的ActiveRecord :: RecordNotFound #update" 无法找到ID = 245的角色 "
如何将数组传递给hidden_field?
有没有办法一次插入多个记录而不是一个?
我有一个非常非常丑陋的rake任务,正在执行以下操作......
VoteRecord.create(:prospect_id => prospect.id, :state => "OH", :election_type => "PR", :election => "2000-03-07", :party => row[45], :participate => participated(row[45]))
VoteRecord.create(:prospect_id => prospect.id, :state => "OH", :election_type => "GE", :election => "2000-11-07", :party => row[46], :participate => participated(row[46]))
VoteRecord.create(:prospect_id => prospect.id, :state => "OH", :election_type => "SP", :election => "2000-05-08", :party => row[47], :participate => participated(row[47]))
VoteRecord.create(:prospect_id => prospect.id, :state => "OH", :election_type => "GE", :election => "2001-11-06", :party => row[48], :participate => participated(row[48]))
VoteRecord.create(:prospect_id => prospect.id, :state => "OH", …Run Code Online (Sandbox Code Playgroud) 我只是想拉.我有更改无视,我的Gemfile和Gemlock文件,我很乐意只是覆盖它们而只是拉.我试着把我的变化藏起来,这对我来说没有用.我该怎么办?
git pull
M Gemfile
U Gemfile.lock
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
~/projects/sms/apps2/apps2_admin(apps2)$ git stash save "saved"
Gemfile.lock: needs merge
Gemfile.lock: needs merge
Gemfile.lock: unmerged (4ea16799dba7bfe1db28adecf36dee1af5195c1a)
Gemfile.lock: unmerged (e77439c9f86d1d0eda7ae0787e3e158f90959e68)
Gemfile.lock: unmerged (d690d3860db1aa8e46c1bb2f4de3e52a297b5c26)
fatal: git-write-tree: error building trees
Cannot save the current index state
~/projects/sms/apps2/apps2_admin(apps2)$ git pull
M Gemfile
U Gemfile.lock
Pull is …Run Code Online (Sandbox Code Playgroud) 我正在使用带有大量数据的ruby CSV.read.库有时会遇到格式不正确的行,例如:
"Illegal quoting in line 53657."
Run Code Online (Sandbox Code Playgroud)
忽略该行并跳过它,然后遍历每个csv并修复格式将更容易.我怎样才能做到这一点?
选择有意义.但有人可以解释.对我有所帮助吗?我不明白这些数据.
>> [1,2,3,4,5,6,7].detect { |x| x.between?(3,4) }
=> 3
>> [1,2,3,4,5,6,7].detect { |x| x.between?(3,6) }
=> 3
>> [1,2,3,4,5,6,7].detect { |x| x.between?(3,7) }
=> 3
>> [1,2,3,4,5,6,7].detect { |x| x.between?(2,7) }
=> 2
>> [1,2,3,4,5,6,7].detect { |x| x.between?(1,7) }
=> 1
>> [1,2,3,4,5,6,7].detect { |x| x.between?(6,7) }
=> 6
>> [1,2,3,4,5,6,7].select { |x| x.between?(6,7) }
=> [6, 7]
>> [1,2,3,4,5,6,7].select { |x| x.between?(1,7) }
=> [1, 2, 3, 4, 5, 6, 7]
Run Code Online (Sandbox Code Playgroud) 我正在跟踪一个名为pry的红宝石宝石上的屏幕.在8:10,使用.tree命令,我相信这是一个Unix命令.
它似乎不适用于我的系统:
[24] pry(main)> .tree
\Error: there was a problem executing system command: tree
Run Code Online (Sandbox Code Playgroud)
我已经将问题追溯到这里,其中pry引用了一个shell命令:
Pry::CommandSet.new do
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
if cmd =~ /^cd\s+(.+)/i
dest = $1
begin
Dir.chdir File.expand_path(dest)
rescue Errno::ENOENT
output.puts "No such directory: #{dest}"
end
else
if !system(cmd)
output.puts "Error: there was a problem executing system command: #{cmd}"
end
end
end
Run Code Online (Sandbox Code Playgroud)
从bash的上下文我尝试使用命令树没有运气:
projects/sms(apps2)$ tree
-bash: tree: command …Run Code Online (Sandbox Code Playgroud) 你熟悉这个错误吗?我不知道如何解决这个问题:
Installing json (1.6.3) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/boris/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb creating Makefile
make /usr/bin/gcc-4.2 -I.
-I/Users/boris/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-darwin10.8.0
-I/Users/boris/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward
-I/Users/boris/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -O3 -Wall -o parser.o -c parser.c make: /usr/bin/gcc-4.2: No such file or directory make: *** [parser.o] Error 1
Gem files will remain installed in /Users/boris/.rvm/gems/ruby-1.9.2-p290@apps2/gems/json-1.6.3 for inspection. Results logged to /Users/boris/.rvm/gems/ruby-1.9.2-p290@apps2/gems/json-1.6.3/ext/json/ext/parser/gem_make.out An error occured while installing json (1.6.3), and …Run Code Online (Sandbox Code Playgroud)