こんがりぃ

都内在住フリーランスのエンジニア。主にRuby on Rails。Twitter(@Kongari_Bug)で格ゲー。

Rails

Rails: enumerizeでselect box用の配列を作る

class A extend Enumerize enumerize :status, in: { pending: 0, in_progress: 1, completed: 2 } end A.status.values.map { |v| [v.text, v.value] }

Ransackの検索用ラベルから検索述語を削除してattribute名を得る

Class: Ransack::Predicate — Documentation for ransack (1.7.0) ↑で検索述語が取れるので label = "hogehoge_cont" label.gsub(/_#{Ransack::Predicate.detect_from_string(label).to_s}\z/, '') など。 or などは取れないので注意。

Rails: selectボックスでrequired: trueにしたときinclude_blank: falseがきかない

環境 Rails: 5.2.2 Ruby: 2.5.3 問題 題名の通り。今回やりたかったことは「選択してください」みたいな選択肢を入れるので空白の選択肢は必要なかった。 結論 そういうものらしい? `select` form helpers with `required: true` generate a blank option e…

RailsのwebpackerにおけるCSSインポート時のrequire, importによる違い

環境 Rails 5.2.2 Ruby 2.5.3 webpacker 3.5.5 概要 webpackerを使ってCSSを利用するため、jsファイルにCSSをインポートする必要があり、以下の2つの書き方がある // application.js require('../stylesheets/application.scss') // application.js import(…

rails/webpackerを使ってRailsで定義した定数をTypeScript(JavaScript)内で使う

環境 Rails5.1.4 rails/webpacker 3.2.1 公式のdocumentにあるerb-loaderを利用する。 https://github.com/rails/webpacker#erb ubuntu@ubuntu-xenial:~/rails/yuyuyui$ bundle exec rails webpacker:install:erb rails aborted! Don't know how to build ta…

Rails5.1 + Angular4で templateUrl, styleUrlsの代替

以前紹介したとおりRails5.1+rails webpackでtemplateUrlを使うことはできない。 Rails5.1.2でAngularを使うとtemplateUrlでエラーが出る - こんがりぃ ちなみにドキュメントがReadmeからdocディレクトリに移ったみたい。 webpacker/typescript.md at master…

Rails5.1.2でAngularを使うとtemplateUrlでエラーが出る

概要 エラーの出るソース import { Component } from '@angular/core'; @Component({ selector: 'hello-angular', templateUrl: './app.component.html' }) export class AppComponent { name = 'Angular!'; } エラー内容 サーバ側 ActionController::Routin…

Rails5.1.1 であとから webpack を有効にする方法

gem 'webpacker', github: 'rails/webpacker' をGemfileに追加 github.com

Rails5.1.0 で React を導入するときに詰まったNode.jsエラー: Node.js not installed.

環境 Ubuntu16.04 Ruby2.4.1 Rails5.1.0 rails new したあとに rails webpacker:install:react すればよいと聞いていたのでやってみるがエラーが出た $ bundle exec rails webpacker:install:react Node.js not installed. Please download and install Node…