Category - Ruby

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

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

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


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

class ApplicationController
before_filter :record_user_activity

private

def record_user_activity
if current_user
current_user.touch :last_active_at
end
end
end

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 'https://rubygems.org/'` 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 https://github.com/rbenv/rbenv.git ~/.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 https://github.com/rbenv/ruby-build.git "$(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-6.0.2.1.gem
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-6.0.2.1.gem
Fetching actionpack-6.0.2.1.gem
Fetching activemodel-6.0.2.1.gem
Fetching activerecord-6.0.2.1.gem
Fetching globalid-0.4.2.gem
Fetching activejob-6.0.2.1.gem
Fetching websocket-extensions-0.1.4.gem
Fetching mini_mime-1.0.2.gem
Fetching mail-2.7.1.gem
Fetching actionmailer-6.0.2.1.gem
Fetching nio4r-2.5.2.gem
Fetching actioncable-6.0.2.1.gem
Fetching mimemagic-0.3.4.gem
Fetching websocket-driver-0.7.1.gem
Fetching marcel-0.3.3.gem
Fetching activestorage-6.0.2.1.gem
Fetching actionmailbox-6.0.2.1.gem
Fetching actiontext-6.0.2.1.gem
Fetching thor-1.0.1.gem
Fetching method_source-0.9.2.gem
Fetching railties-6.0.2.1.gem
Fetching sprockets-4.0.0.gem
Fetching sprockets-rails-3.2.1.gem
Fetching rails-6.0.2.1.gem
Successfully installed zeitwerk-2.3.0
Successfully installed activesupport-6.0.2.1
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-6.0.2.1
Successfully installed actionpack-6.0.2.1
Successfully installed activemodel-6.0.2.1
Successfully installed activerecord-6.0.2.1
Successfully installed globalid-0.4.2
Successfully installed activejob-6.0.2.1
Successfully installed mini_mime-1.0.2
Successfully installed mail-2.7.1
Successfully installed actionmailer-6.0.2.1
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-6.0.2.1
Successfully installed mimemagic-0.3.4
Successfully installed marcel-0.3.3
Successfully installed activestorage-6.0.2.1
Successfully installed actionmailbox-6.0.2.1
Successfully installed actiontext-6.0.2.1
Successfully installed thor-1.0.1
Successfully installed method_source-0.9.2
Successfully installed railties-6.0.2.1
Successfully installed sprockets-4.0.0
Successfully installed sprockets-rails-3.2.1
Successfully installed rails-6.0.2.1
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-6.0.2.1
Installing ri documentation for actionview-6.0.2.1
Parsing documentation for actionpack-6.0.2.1
Installing ri documentation for actionpack-6.0.2.1
Parsing documentation for activemodel-6.0.2.1
Installing ri documentation for activemodel-6.0.2.1
Parsing documentation for activerecord-6.0.2.1
Installing ri documentation for activerecord-6.0.2.1
Parsing documentation for globalid-0.4.2
Installing ri documentation for globalid-0.4.2
Parsing documentation for activejob-6.0.2.1
Installing ri documentation for activejob-6.0.2.1
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-6.0.2.1
Installing ri documentation for actionmailer-6.0.2.1
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-6.0.2.1
Installing ri documentation for actioncable-6.0.2.1
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-6.0.2.1
Installing ri documentation for activestorage-6.0.2.1
Parsing documentation for actionmailbox-6.0.2.1
Installing ri documentation for actionmailbox-6.0.2.1
Parsing documentation for actiontext-6.0.2.1
Installing ri documentation for actiontext-6.0.2.1
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-6.0.2.1
Installing ri documentation for railties-6.0.2.1
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-6.0.2.1
Installing ri documentation for rails-6.0.2.1
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
Rails 6.0.2.1

read more

rbenv update

rbenvを個別にインストールしている場合

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

read more

Railsアセットパイプラインのパス確認

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


コンパイル
$ rake assets:precompile RAILS_ENV=production

config/production.rbファイル内の記述のうち
config.assets.compile = false
の記述を見つけ、「falseをtrueに書き換えて」保存します。

read more

Ruby on Rail インストール  Linux編

http://www.ruby-lang.org/ja/ ここからアーカイブをダウンロードします
 
Ruby本体をインストールします
tar xvzf ruby-1.8.4.tar.gz
cd ruby-1.8.4
ls
./configure
make
make install

Gemをインストール
tar xvzf rubygems-0.8.11.tgz
cd rubygems-0.8.11
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

Railsをインストール
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: http://gems.rubyforge.org
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...

Railsのコマンドが使えることを確認

read more

Recent entry

Search

Tag Cloud

Page Top