網頁

2011年8月28日 星期日

[ROR]Could not find a JavaScript runtime.

執行 rails server 發生下列錯誤: 


/usr/local/lib/ruby/gems/1.9.1/gems/execjs-1.2.0/lib/execjs/runtimes.rb:46:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

解決方式: 

參考

https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

安裝 node.js

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

如果還是不行:

安裝 gem 


gem install execjs --no-ri --no-rdoc

gem install therubyracer --no-ri --no-rdoc
 
並且修改專案目錄內的 Gemfile
 
加入
 
gem 'execjs'
 
gem 'therubyracer'
 
之後在執行
 
 rails s



2011年8月22日 星期一

git-clone指定branch


有时git clone下来会出现很多branch,更麻烦的是如果主分支没代码那你就只能看到.git目录了。如下面的这个:
  发现本地就只有一个.git目录,那么这个时候就需要checkout了。
  进入你的本地目录,如这个是mesa,利用
$ git branch –r
  查看branch信息(当然你也可以用git show-branch查看,不过有时并不好用),获得如下branch信息:
origin/android
origin/mesa-es
origin/mesa-es-dri
  此时我们需要的是android分支的代码,那么此时就要进行checkout了。
$ git checkout origin/android
  你再看你的目录(mesa)下是不是有了代码了?其它的branch同理。



from : http://wangliping.net/git-clone-spec-branch

2011年8月15日 星期一

2011年8月3日 星期三

rails 常用的 gem


Rails的插件很豐富,並且大部分都放在github,非常方便修改
這裡簡單介紹我使用過的Rails插件

實體相關

restful_authentication

[必備]生成用戶實體,restful登錄project
 

mislav-will_paginate

[必備]分頁project
 

annotate_models

在實體類文件頭部顯示字段信息project

paperclip

用於上傳附件,並可對圖片進行縮放(需要imagemagick)
可對上傳的附件進行文件大小的校驗project



2011年8月2日 星期二

使用simple form 生成 select

使用下列語法可以生成select
<%= f.input :cat_id, :collection => @cats , :label => "分類" %>

但用這方法生成的select 的第一個選項會是空白


使用下列語法,可以把第一個空白選項取消
<%= f.input :cat_id, :collection => @cats ,:include_blank => false, :label => "分類" %>


或者可用 :prompt ,預設第一個選項的文字
<%= f.input :cat_id, :collection => @cats ,:include_blank => false,:prompt=>'請選一個分類' , :label => "分類" %>

切換rails rake 版本 (Switching rails rake version)


有些時候取得一些 rails 的程式,要執行  rake db:create  時會發生

You have already activated rake 0.9.x, but your Gemfile requires rake 0.x.x

這是會想要切換版本

$rake -V   # v大寫可以得到目前rake 的版本

想要改變rake 版本要直接修改rake設定檔 
執行編輯
vim ~/.rvm/gems/ruby-1.8.7-p334/bin/rake
修改裡面的 version  =  "0.X.X"   改成你想預設的版本

$ vim ~/.rvm/gems/ruby-1.8.7-p334/bin/rake

#!/home/tomcat/.rvm/rubies/ruby-1.8.7-p334/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end
gem 'rake', version
load Gem.bin_path('rake', 'rake', version)

LinkWithin

Related Posts with Thumbnails