ホーム > 2012 > 2月

cap deploy で “rake: command not found” というエラーが発生した場合

cap deploy したら bundle install の最中に failed: "sh -c 'cd /deploy/releases/20120229025926 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'" on example.com というエラーが発生して途中で止まったしまった。

.ssh/environment に以下を追記したら解決した

PATH=/usr/local/ruby-1.9.2/bin:/usr/local/bin:/bin:/usr/bin

cap deploy で “invalid byte sequence in US-ASCII” というエラーが発生した場合

cap deploy したら bundle install の最中に "invalid byte sequence in US-ASCII" というエラーが発生して途中で止まったしまった。

.ssh/environment に以下を追記したら解決した

LC_CTYPE=ja_JP.utf8
LANG=ja_JP.utf8

Rails で Carrierwave を使う

Gemfile に追加する

gem 'carrierwave', :git => 'https://github.com/jnicklas/carrierwave.git'

Gemfile に追加したらインストール

$ bundle install

アップローダークラスの作成

$ rails generate uploader image
      create  app/uploaders/image_uploader.rb

Rails で simple_form を使う

Gemfile に追加する

gem 'simple_form'

Gemfile に追加したらインストール

$ bundle install

simple_form の導入。 Bpotstrap を使うのでオプションをつける

$ rails generate simple_form:install --bootstrap
       exist  config
      create  config/initializers/simple_form.rb
      create  config/locales/simple_form.en.yml
      create  lib/templates/erb/scaffold/_form.html.erb
===============================================================================

  Be sure to have a copy of the Bootstrap stylesheet available on your
  application, you can get it on http://twitter.github.com/bootstrap.

  Inside your views, use the 'simple_form_for' with one of the Bootstrap form
  classes, '.form-horizontal', '.form-inline', '.form-search' or
  '.form-vertical', as the following:

    = simple_form_for(@user, :html => {:class => 'form-horizontal' }) do |form|

===============================================================================

デフォルトのフォームを hml5対応にして、 horizontal に変更

diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb
index 2ebb17b..c568fb1 100644
--- a/config/initializers/simple_form.rb
+++ b/config/initializers/simple_form.rb
@@ -46,8 +46,13 @@ SimpleForm.setup do |config|
   end

   config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
+    b.use :html5
     b.use :placeholder
     b.use :label
+    b.optional :maxlength
+    b.optional :pattern
+    b.optional :min_max
+    b.optional :readonly
     b.wrapper :tag => 'div', :class => 'controls' do |ba|
       ba.use :input
       ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
@@ -133,7 +138,7 @@ SimpleForm.setup do |config|
   config.label_class = 'control-label'

   # You can define the class to use on all forms. Default is simple_form.
-  # config.form_class = :simple_form
+  config.form_class = 'form-horizontal'

   # You can define which elements should obtain additional classes
   # config.generate_additional_classes_for = [:wrapper, :label, :input]

参考

Rails で Bootstrap を使う

Gemfile の group :assets do ... end の中に追加する

gem 'twitter-bootstrap-rails', :git => 'http://github.com/seyhunak/twitter-bootstrap-rails.git'

Gemfile に追加したらインストール

$ bundle install

Bootstrap の導入

$ rails generate bootstrap:install
      insert  app/assets/javascripts/application.js
      create  app/assets/javascripts/bootstrap.js.coffee
      create  app/assets/stylesheets/bootstrap_and_overrides.css.less
        gsub  app/assets/stylesheets/application.css
        gsub  app/assets/stylesheets/application.css

レイアウトの作成

$ rails generate bootstrap:layout application fluid
    conflict  app/views/layouts/application.html.erb
Overwrite /home/nakajima/Documents/Work/warehouse/app/views/layouts/application.html.erb? (enter "h" for help) [Ynaqdh] y
       force  app/views/layouts/application.html.erb

確認してみる

$ rails generate scaffold Product title:string
$ rake db:migrate

generate で作成したレイアウトは Bootstrap の Example などを参考にして調整したほうがいい。

Page 1 of 212

About

mooco
[mooco]

東京を中心にWebデザイナーとして活動しています。

趣味は愛猫と遊ぶこと。 web周りのあれこれで遊ぶことです。

Search

Categories