Category - Ruby on Rails

bundle update mimemagic

Fetching gem metadata from https://rubygems.org/.......
Your bundle is locked to mimemagic (0.3.3), but that version could not be found
in any of the sources listed in your Gemfile. If you haven't changed sources,
that means the author of mimemagic (0.3.3) has removed it. You'll need to update
your bundle to a version other than mimemagic (0.3.3) that hasn't been removed
in order to install.


こんなのが出た時は

bundle update mimemagic

read more

Rails6 select2 導入

$ yarn add tempusdominus-bootstrap-4
$ yarn add jquery
$ yarn add jquery-ui
$ yarn add select2

・app/javascript/packs/application.js
require('jquery')
require('jquery-ui')
import 'bootstrap'
import "../stylesheets/application"
import 'jquery-ui/themes/base/core.css';
import 'jquery-ui/themes/base/menu.css';
import 'jquery-ui/themes/base/autocomplete.css';
import 'jquery-ui/themes/base/theme.css';
import 'select2/dist/css/select2.css';


・app/javascript/stylesheets/application.scss
@import 'bootstrap';
@import "~tempusdominus-bootstrap-4/src/sass/tempusdominus-bootstrap-4";


<select id="multiple" class="multiple" multiple="multiple">
<option value="value1">value1</option>
<option value="value2">value2</option>
<option value="value3">value3</option>
<option value="value4">value4</option>
<option value="value5">value5</option>
</select>


$(function () {
$('#multiple').select2({
placeholder: 'Please Select',
allowClear: true,
dropdownAutoWidth: true,
width: 'auto',
multiple: true
})
});

解除する場合は
$('#multiple').val(null).trigger('change');

read more

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

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

Recent entry

Search

Tag Cloud

Page Top