2012年3月7日水曜日

emacsのC-h

そう。これを多用するのですが、設定していなかったので設定します。
ついでに、AutoCompleteも入れました。
➡ http://cx4a.org/software/auto-complete/index.ja.html

んで、.emacsはこんな感じ。


(global-set-key "\C-h" 'delete-backward-char)
(setq inhibit-startup-message t)
(add-to-list 'load-path "~/.emacs.d")
;(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict/")
(require 'auto-complete-config)
(ac-config-default)


4行目は、AutoComplete入れたら追加しろって書いてあったので、入れたらError。
コメントアウトしたら動いたので、このままにしておきます。

ちなみに、最初の1行目はC-hをbackspaceに。
2行目はEmacsの最初に出てくる表示を消してます。

今日はこんな感じ。

2012年3月6日火曜日

oauthとか。

続いて、oauth。

こちら⬇を見ながら、oauth。
http://gihyo.jp/dev/serial/01/heroku/0004




$ rails s
Could not find gem 'oa-oauth (>= 0) ruby' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.


でサーバ起動して、エラー。

oauthがねーってよ。

$ sudo gem install oauth

でインストール。
これだけだとダメ。

$ bundle install --without production

をして、oauthバンドルをインストールする。
そしたら、サーバ起動成功。

でも、こんなエラー。


Started GET "/" for 127.0.0.1 at 2012-03-06 01:44:10 +0900

NoMethodError (undefined method `include?' for nil:NilClass):
  oa-core (0.2.4) lib/omniauth/builder.rb:29:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.1) lib/rack/etag.rb:23:in `call'
  rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__3696322542728200147__call__1660822934616839522__callbacks'
  activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.2.1) lib/rails/engine.rb:479:in `call'
  railties (3.2.1) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Users/<MyPCname>/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /Users/<MyPCname>/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /Users/<MyPCname>/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'


ふんふん。もう今日は無理なので、明日見ます。
オヤスミ。

2012年3月5日月曜日

gitとか。

今週は前回までの、

$ heroku rake db:migrate

について、何が問題だったのかが不明だったので、少し探りを入れてみた。
新しいプロジェクト(単位が違う?)を作って、今までの作業を試してみた。

具体的には、
$ rails new ruby_test
$ git init
$ git add .
$ git commit -m "Init"

としておいて、

$ heroku create でアプリケーションを作っておいて
$ git push heroku master

でherokuに送信。

まぁ、ここまでは単純なので、簡単に動きましたが、ここから

$ rails g scaffold Product name:string price:float url:string
$ rake db:migrate
$ rm public/index.html

ってしてから、
config/routes.rbに、以下を追記。

root :to => "products#index"

ここまでで、
$ rails s
ってやると、動作確認OK!

だけど、
$ git add .
$ git rm public/index.html
$ git commit -m "Scaffold products"
$ git push heroku master

ってからの

$ heroku rake db:migrate

で、またつまづきました。orz
でも、過去の経験を活かし、

$ gem install pg

をしてから、Gemfileに以下を追加


group :production do
 gem 'pg'
end
group :development, :test do
 gem 'sqlite3'
end
ちなみに、元々記述してあった

gem 'sqlite3'

は削除しました。


んで、

$ git add .
をして
$ git commit -m "Scaffold products"
[master 1a0d0ed] Scaffold products
 Committer: <Myname> <<MyPCname>@<MyAccount>.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 files changed, 6 insertions(+), 1 deletions(-)


$ git commit -m "Init"
# On branch master
nothing to commit (working directory clean)

うん、ちゃんと動いていない。
取りあえず、よくわからないので、

$ gem install postgres

をしてみるが、意味なさそう。。。

んで、次は、

sudo gem install pg -- --with-pg-dir=/opt/local/lib/postgresql90

をしてみる。これでもダメ。
よーわからんが、取りあえず

git push heroku master

で、マスターに送信!

$ git push heroku master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 369 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Detected Rails is not set to serve static_assets
       Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
       Installing rails3_disable_x_sendfile... done
-----> Configure Rails to log to stdout
       Installing rails_log_stdout... done
-----> Gemfile detected, running Bundler version 1.0.7
       Unresolved dependencies detected; Installing...
       Using --without development:test
       You have modified your Gemfile in development but did not check
       the resulting snapshot (Gemfile.lock) into version control
       
       You have added to the Gemfile:
       * pg
       FAILED: http://devcenter.heroku.com/articles/bundler
 !     Heroku push rejected, failed to install gems via Bundler

To git@heroku.com:<MyAppName>.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:<MyAppName>.git'


うん、何か失敗しとるぞ。どれどれ。。。

pg追加しろとか書いてあるぞ。。。
でも、追加したんですけど。。。

よくよく見ると、
$ git commit -m "test"
でうまくコミットできてない。orz

あ、そういえば、Bundler入れてないなー。
ということで、

gem install bundler

してみるもダメ。

でも、

$ bundle install --without production

をしてみて

$ git commit -a

でコミットして、

$ git push heroku master

したら、うまくコミットできたよ!

そして、問題の

heroku rake db:migrate

もうまくいったよ!

問題の原因がわかったよ。

原因は確かにpgが入っていない事だったんだけど、
それをちゃんとherokuにコミットできていなかったんだね。。。orz

取りあえず、すっきりしたので、次回からは次のステップへ!って同じ事書いてる?www

あ、でも気になる事を1つだけ。

今から作るアプリ、postgresql使う予定なんだけど、sqlite3とか言ってるよ。。。