Category - Ruby

Ruby Devise 最終アクティブ時間の記録

Devise モデルじゃなくてもいいかもしれないけど・・・

カラム last_active_at datetime型をテーブルに追加

こんなふうにしてアクティ時間を更新させたいタイミングで touch メソッドを呼ぶ

class ApplicationController
before_filter :record_user_activity


def record_user_activity
if current_user
current_user.touch :last_active_at

read more

An error occurred while installing mysql2 (0.4.10), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.4.10' --source ''` succeeds before bundling.

bundle install できない場合

$ brew info openssl
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
$ bundle config --local build.mysql2 "--with-cppflags=-I/usr/local/opt/openssl/include"
$ bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

$ bundle install --path vendor/bundle

read more

Ruby on Rails モデルの削除

# rails destroy model モデル名
# rails generate migration drop_table_モデル名s
# rake db:migrate


% bin/rails destroy model Bookmark
Running via Spring preloader in process 65220
invoke active_record
remove db/migrate/20200314041531_create_bookmarks.rb
remove app/models/bookmark.rb
invoke test_unit
remove test/models/bookmark_test.rb
remove test/fixtures/bookmarks.yml

read more

Rails 6 インストール後

Webpacker configuration file not found /Users/cano/personal/rails/RailsApp/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/[USER]/personal/rails/RailsApp/config/webpacker.yml (RuntimeError)

% brew install yarn
% rails webpacker:install
% rails s

read more

Mac rbenv

# git clone ~/.rbenv
# cd ~/.rbenv && src/configure && make -C src

# vi .bash_profile

# rbenv
export RBENV_ROOT="$HOME/.rbenv"
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

# source ~/.bash_profile

# mkdir -p "$(rbenv root)"/plugins
# git clone "$(rbenv root)"/plugins/ruby-build
# rbenv install 2.7.0
# rbenv global 2.7.0
# gem install railties && rbenv rehash
# gem install sqlite3 puma sass-rails uglifier coffee-rails jquery-rails turbolinks jbuilder byebug web-console listen spring spring-watcher-listen
# gem update --system
# gem update

read more

You don't have write permissions for the /usr/bin directory.

% sudo gem install rails
Fetching zeitwerk-2.3.0.gem
Fetching activesupport-
Fetching rack-2.2.2.gem
Fetching rack-test-1.1.0.gem
Fetching crass-1.0.6.gem
Fetching loofah-2.4.0.gem
Fetching rails-html-sanitizer-1.3.0.gem
Fetching rails-dom-testing-2.0.3.gem
Fetching builder-3.2.4.gem
Fetching erubi-1.9.0.gem
Fetching actionview-
Fetching actionpack-
Fetching activemodel-
Fetching activerecord-
Fetching globalid-0.4.2.gem
Fetching activejob-
Fetching websocket-extensions-0.1.4.gem
Fetching mini_mime-1.0.2.gem
Fetching mail-2.7.1.gem
Fetching actionmailer-
Fetching nio4r-2.5.2.gem
Fetching actioncable-
Fetching mimemagic-0.3.4.gem
Fetching websocket-driver-0.7.1.gem
Fetching marcel-0.3.3.gem
Fetching activestorage-
Fetching actionmailbox-
Fetching actiontext-
Fetching thor-1.0.1.gem
Fetching method_source-0.9.2.gem
Fetching railties-
Fetching sprockets-4.0.0.gem
Fetching sprockets-rails-3.2.1.gem
Fetching rails-
Successfully installed zeitwerk-2.3.0
Successfully installed activesupport-
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.


% sudo gem install rails -n /usr/local/bin
Successfully installed rack-2.2.2
Successfully installed rack-test-1.1.0
Successfully installed crass-1.0.6
Successfully installed loofah-2.4.0
Successfully installed rails-html-sanitizer-1.3.0
Successfully installed rails-dom-testing-2.0.3
Successfully installed builder-3.2.4
Successfully installed erubi-1.9.0
Successfully installed actionview-
Successfully installed actionpack-
Successfully installed activemodel-
Successfully installed activerecord-
Successfully installed globalid-0.4.2
Successfully installed activejob-
Successfully installed mini_mime-1.0.2
Successfully installed mail-2.7.1
Successfully installed actionmailer-
Building native extensions. This could take a while...
Successfully installed nio4r-2.5.2
Successfully installed websocket-extensions-0.1.4
Building native extensions. This could take a while...
Successfully installed websocket-driver-0.7.1
Successfully installed actioncable-
Successfully installed mimemagic-0.3.4
Successfully installed marcel-0.3.3
Successfully installed activestorage-
Successfully installed actionmailbox-
Successfully installed actiontext-
Successfully installed thor-1.0.1
Successfully installed method_source-0.9.2
Successfully installed railties-
Successfully installed sprockets-4.0.0
Successfully installed sprockets-rails-3.2.1
Successfully installed rails-
Parsing documentation for rack-2.2.2
Installing ri documentation for rack-2.2.2
Parsing documentation for rack-test-1.1.0
Installing ri documentation for rack-test-1.1.0
Parsing documentation for crass-1.0.6
Installing ri documentation for crass-1.0.6
Parsing documentation for loofah-2.4.0
Installing ri documentation for loofah-2.4.0
Parsing documentation for rails-html-sanitizer-1.3.0
Installing ri documentation for rails-html-sanitizer-1.3.0
Parsing documentation for rails-dom-testing-2.0.3
Installing ri documentation for rails-dom-testing-2.0.3
Parsing documentation for builder-3.2.4
Installing ri documentation for builder-3.2.4
Parsing documentation for erubi-1.9.0
Installing ri documentation for erubi-1.9.0
Parsing documentation for actionview-
Installing ri documentation for actionview-
Parsing documentation for actionpack-
Installing ri documentation for actionpack-
Parsing documentation for activemodel-
Installing ri documentation for activemodel-
Parsing documentation for activerecord-
Installing ri documentation for activerecord-
Parsing documentation for globalid-0.4.2
Installing ri documentation for globalid-0.4.2
Parsing documentation for activejob-
Installing ri documentation for activejob-
Parsing documentation for mini_mime-1.0.2
Installing ri documentation for mini_mime-1.0.2
Parsing documentation for mail-2.7.1
Installing ri documentation for mail-2.7.1
Parsing documentation for actionmailer-
Installing ri documentation for actionmailer-
Parsing documentation for nio4r-2.5.2
Installing ri documentation for nio4r-2.5.2
Parsing documentation for websocket-extensions-0.1.4
Installing ri documentation for websocket-extensions-0.1.4
Parsing documentation for websocket-driver-0.7.1
Installing ri documentation for websocket-driver-0.7.1
Parsing documentation for actioncable-
Installing ri documentation for actioncable-
Parsing documentation for mimemagic-0.3.4
Installing ri documentation for mimemagic-0.3.4
Parsing documentation for marcel-0.3.3
Installing ri documentation for marcel-0.3.3
Parsing documentation for activestorage-
Installing ri documentation for activestorage-
Parsing documentation for actionmailbox-
Installing ri documentation for actionmailbox-
Parsing documentation for actiontext-
Installing ri documentation for actiontext-
Parsing documentation for thor-1.0.1
Installing ri documentation for thor-1.0.1
Parsing documentation for method_source-0.9.2
Installing ri documentation for method_source-0.9.2
Parsing documentation for railties-
Installing ri documentation for railties-
Parsing documentation for sprockets-4.0.0
Installing ri documentation for sprockets-4.0.0
Parsing documentation for sprockets-rails-3.2.1
Installing ri documentation for sprockets-rails-3.2.1
Parsing documentation for rails-
Installing ri documentation for rails-
Done installing documentation for rack, rack-test, crass, loofah, rails-html-sanitizer, rails-dom-testing, builder, erubi, actionview, actionpack, activemodel, activerecord, globalid, activejob, mini_mime, mail, actionmailer, nio4r, websocket-extensions, websocket-driver, actioncable, mimemagic, marcel, activestorage, actionmailbox, actiontext, thor, method_source, railties, sprockets, sprockets-rails, rails after 37 seconds
32 gems installed

% rails -v

read more

rbenv update


% cd ~/.rbenv/plugins/ruby-build
% git pull
% rbenv install --list

read more


$ rails c
> Rails.application.config.assets.paths

$ rake assets:precompile RAILS_ENV=production

config.assets.compile = false

read more

Ruby on Rail インストール  Linux編 ここからアーカイブをダウンロードします
tar xvzf ruby-1.8.4.tar.gz
cd ruby-1.8.4
make install

tar xvzf rubygems-0.8.11.tgz
cd rubygems-0.8.11
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

gem install rails

[root@localhost]# gem install rails
Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
Updating Gem source index for:
Install required dependency rake? [Yn] Y
Install required dependency activesupport? [Yn] Y
Install required dependency activerecord? [Yn] Y
Install required dependency actionpack? [Yn] Y
Install required dependency actionmailer? [Yn] Y
Install required dependency actionwebservice? [Yn] Y
Successfully installed rails-1.1.6
Successfully installed rake-0.7.1
Successfully installed activesupport-1.3.1
Successfully installed activerecord-1.14.4
Successfully installed actionpack-1.12.5
Successfully installed actionmailer-1.2.5
Successfully installed actionwebservice-1.1.6
Installing RDoc documentation for rake-0.7.1...
Successfully installed activesupport-1.3.1
Successfully installed activerecord-1.14.4
Successfully installed actionpack-1.12.5
Successfully installed actionmailer-1.2.5
Successfully installed actionwebservice-1.1.6
Installing RDoc documentation for rake-0.7.1...
Installing RDoc documentation for activesupport-1.3.1...
Installing RDoc documentation for activerecord-1.14.4...
Installing RDoc documentation for actionpack-1.12.5...
Installing RDoc documentation for actionmailer-1.2.5...
Installing RDoc documentation for actionwebservice-1.1.6...


read more

Recent entry


Tag Cloud

Page Top