Skip to content

Instantly share code, notes, and snippets.

@taketo1113
taketo1113 / README: Output csv file with Shift JIS.md
Last active November 9, 2021 07:03
Output csv file with Shift JIS using csb gem
@taketo1113
taketo1113 / README: Rails HostAuthorization setting to Allow any hosts.md
Created August 1, 2020 02:18
Rails HostAuthorization setting to Allow any hosts

Rails HostAuthorization setting to Allow any hosts

  • config
Rails.application.config.hosts << /.*/
  • env
    • rails 6.0.3.2
@taketo1113
taketo1113 / README: vue component per form controls.md
Last active March 4, 2020 04:02
vue component per form controls

Design Pattern to create vue component per form controls

Background

Rails MPA + Vue.js

Files

  • Rails View: app/views/views/_form.slim
  • Vue SFC: components/equipment_form/
    • index.js
  • EquipmentFormDeviceId.vue
@taketo1113
taketo1113 / pundit_nested_headless_policies.md
Last active December 21, 2018 08:46
Pundit Nested Headless policies

Pundit Nested Headless policies

# app/policies/hoge/dashboard_policy.rb
class Hoge::DashboardPolicy < Struct.new(:user, :dashboard)
  # ...
end
@taketo1113
taketo1113 / Replace 'be_success' to 'be_successful'.md
Created May 11, 2018 02:13
Fix 'DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful?'
  • Error
DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful?
  • Sample code
  # deprecated
  expect(response).to be_success
 
@taketo1113
taketo1113 / request_macros.rb
Last active March 2, 2018 01:12
Rails Request Spec Sample
# spec/support/request_macros.rb
module RequestMacros
def request_login_user
before(:each) do
@loginuser = FactoryBot.create(:login_user)
post user_session_path, params: { user: { email: @loginuser.email, password: @loginuser.password } }
follow_redirect!
end
end
end
@taketo1113
taketo1113 / Usage Committee.md
Last active January 1, 2018 14:11
Usage Committee

Usage Committee

Gemfile

  gem 'committee'
  gem 'committee-rails'
@taketo1113
taketo1113 / Replace 'factory_girl' to 'factory_bot'.md
Last active February 4, 2021 03:07
Replace 'factory_girl' to 'factory_bot'

Replace 'factory_girl' to 'factory_bot'

  • edit Gemfile
gem 'factory_bot_rails'
  • gem install
$ bundle install
@taketo1113
taketo1113 / ActiveRecord conditions not containing null or empty.md
Last active October 28, 2017 14:10
How to write an ActiveRecord conditions not containing null or empty

ActiveRecord conditions not containing null or empty

> User.where.not(email: [nil, '']).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE (NOT ((\"users\".\"email\" = '' OR \"users\".\"email\" IS NULL)))"
  • env
    • ruby: 2.4.1
  • rails: 5.0.2
@taketo1113
taketo1113 / Render with locale for view spec.md
Created May 2, 2017 02:11
Render with locale for view spec