安装rvm,更新.gmrc文件,更新rubygems并运行后gem install rails -v ">=3.1.0rc",我现在似乎已经完全搞乱了:
$ rails -v
/usr/local/lib/site_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find rails (>= 0) amongst [] (Gem::LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:1182:in `gem'
from /var/lib/gems/1.8/bin/rails:18
Run Code Online (Sandbox Code Playgroud)
myhome@myhome-mini:~$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [i686-linux]
- INSTALLATION DIRECTORY: /home/myhome/gems
- RUBY EXECUTABLE: /home/myhome/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
- EXECUTABLE DIRECTORY: /home/myhome/gems/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/myhome/gems
- /usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- …Run Code Online (Sandbox Code Playgroud) 我知道我可以使用rand(max)生成随机浮点数.我试图在一个范围内生成一个浮点数,这应该不难.但是例如rand(1.4512)返回0,因此rand不用浮点数计算.现在我尝试了一个小技巧,将事物转换为整数,然后在我想要的范围内随机化一个拟合数,然后将它计算回浮点数......这是不行的.
我的问题是如何以更好的方式做到这一点.如果没有更好的方法,为什么这个不起作用?(也许对我来说太晚了,我应该在2小时前开始睡觉了......).整个过程旨在成为计算数据库记录的"位置"字段的方法,以便用户可以手动订购它们.我之前从未做过这样的事情,也许有人可以用更好的解决方案暗示我.
这是迄今为止的代码:
def calculate_position(@elements, index)
min = @elements[index].position
if @elements[index + 1].nil?
pos = min + 1
else
pos = min + (rand(@elements[index + 1].position * 10000000000) / 10000000000)
end
return pos
end
Run Code Online (Sandbox Code Playgroud)
谢谢!
我想将markdown转换为html.在我的观点中我有,markdown(some_text_variable)但我得到了错误undefined method markdown.
我添加require 'BlueCoth'到enviroment.rb并安装了BlueCloth gem.有谁能够帮我?
在生产高效的盒子上编译资产时,我遇到了类似很多用户的类似问题.唯一的区别是我无法从跟踪中得到任何提示来解决问题.
rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rbenv/versions/1.9.3-p362/bin/ruby /usr/local/rbenv/versions/1.9.3-p362/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Command failed with status (): [/usr/local/rbenv/versions/1.9.3-p362/bin/r...]
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:53:in `block in create_shell_runner'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:45:in `call'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:45:in `sh'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils_ext.rb:39:in `sh'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:80:in `ruby'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils_ext.rb:39:in `ruby'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:29:in …Run Code Online (Sandbox Code Playgroud) 我在实现for循环时遇到问题.我执行脚本时遇到此错误
test1.sh:2:语法错误:循环变量错误
我不明白这个错误.
这是我的剧本
#!/bin/bash
for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times..."
done
Run Code Online (Sandbox Code Playgroud)
任何人都可以在ubuntu中告诉我for循环的语法(在ubuntu中它链接到破折号shell)shell吗?
我刚刚创建了一个从无到有的新的应用程序rails4.0.0.rc1有1.9.3-p374(这要根据导游工作).
但是,我没有做一个简单的动作create.
class Books
def create
@book = Book.new book_params
if @book.save
redirect_to @book
else
render action: :new
end
end
private
def book_params
params.require(:book).permit(:name, :description)
end
end
Run Code Online (Sandbox Code Playgroud)
在这里做一个创建结果a
undefined method `synchronize' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
错误指向的行if @book.save.
那是因为1.9.3或者我错过了什么吗?
在我的rails应用程序中只有json,我想发送一个406代码,只要有人调用我的rails应用程序,接受标头设置为除application/json之外的任何东西.当我将内容类型设置为除application/json之外的任何内容时,我还希望它发送415
我的控制器有respond_to:json穿上它们.我只在所有动作中渲染json.但是,如何确保为所有其他接受标头/内容类型调用的所有调用返回错误代码406/415,并将格式设置为除json之外的任何内容.
例如.如果我的资源是书籍/ 1我想允许books/1.json或books/1 with application/json in accept header and content type
关于我如何做这两个动作的任何想法?
如何在回形针中生成pdf的第一页作为缩略图?
我尝试了很多,但它没有用
has_attached_file :book_url, :styles => {
:thumb => "100x100#",
:small => "150x150>",
:medium => "200x200" }
Run Code Online (Sandbox Code Playgroud)
这是将pdf的名称作为链接,但它没有给出pdf的第一页
<%= link_to 'My PDF', @book.book_url.url %>
Run Code Online (Sandbox Code Playgroud) ruby-on-rails paperclip ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-4
我的Rails应用程序中有以下行:
@images = @product.secondary_images.split(",")
Run Code Online (Sandbox Code Playgroud)
当@ product.secondary_images包含内容时,运行正常.但是,当没有内容时,我收到此错误:
undefined method `split' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
如果没有内容,如何为@images分配另一个值?
$query = $this->createQuery();
return $query->matching($query->like('linker', "$linkerKey=$linkerValue"))
->setOrderings(array('crdate' => $ordering))
->execute();
Run Code Online (Sandbox Code Playgroud)
我怎样才能在extbase中调试这样生成的查询?当再次创建相同的查询(但没有execute())并尝试使用var_dump或内部t3lib_div :: debug显示它时,我只会收到一个空白页面.
ruby ×3
rubygems ×2
bash ×1
dash-shell ×1
for-loop ×1
friendly-id ×1
linux ×1
markdown ×1
mysql ×1
paperclip ×1
rake ×1
rvm ×1
shell ×1
typo3 ×1
typo3-6.2.x ×1
typo3-7.6.x ×1