うちのいぬ Tech Blog

Tech Blog of Uchinoinu/My dog

Rails

Sending HTTP Request with Custon header like "AccessToken" by Almofire, and Getting them by Rails 4.x

GET with Custom Header by Alamofire let URL = NSURL(string: "https://dinner.please")! let mutableURLRequest = NSMutableURLRequest(URL: URL) let message = "I want to eat!" mutableURLRequest.HTTPMethod = "GET" mutableURLRequest.setValue(mess…

AlamofireでRequest Headerに AccessTokenなどを設定してGETで通信して、Rails4.x でそれらを受け取る

忘れていたので、復習の意味でメモ。 AlamofireでCustom HeadersでGET let URL = NSURL(string: "https://onedari.please")! let mutableURLRequest = NSMutableURLRequest(URL: URL) let message = "tabetai" mutableURLRequest.HTTPMethod = "GET" mutable…

How to use URL including dot (decimal point) in Rails 4.x

What I want to do GET http://domain.jp/api/2.1.1/users or GET http://domain.jp/meats/score/21293.02 (You may say URL with parameter including dot is not good....) How I failed config/routes.rb get 'meats/score/:score' => 'meats#score' rout…

Rails4.x で 少数点(. ドット)を含めたURLを使いたい場合

やりたいこと GET http://domain.jp/api/2.1.1/users とか GET http://domain.jp/meats/score/21293.02 とか、少数点、というかドットが入った形のURLを使う方法についてです。 (そもそもドットの入った値はURLに入れないほうが良いのかもしれませんが...)…

rails c(bin/rails c) cannot load env vars managed by direnv

Japanese here uchinoinu.hatenablog.jp Situation Rails 4.2 Ruby 2.3 Spring 1.3.5 direnv 2.8.1 Manage environment variables by direnv run rails command using Spring Problem Adding new environment variables, rails c cannot load any environmen…

direnvで環境変数を管理していて、springへのpathも貼っている場合、環境変数を編集すると、rails cとかで環境変数が読み込めなくなるエラーへの対応

English here uchinoinu.hatenablog.jp 状況 Rails 4.2 Ruby 2.3 Spring 1.3.5 direnv 2.8.1 direnvで環境変数を管理している Springを使ってrailsコマンドを動かしている 問題 環境変数を追加したら、rails sは通るけど、rails cでは環境変数を読み込めなく…

How to embed css(sass) in Slim file

Japanese here. uchinoinu.hatenablog.jp sass: img width: 100% Write like above, <style type="text/css"> img { width: 100%; } </style> Output html like above. Reference マークアッパー的 Slim 入門21の手引き | e2esound.com業務日誌

Slimファイル内に css(sass)を埋め込む方法

English here uchinoinu.hatenablog.jp 簡単でした sass: img width: 100% と書くと <style type="text/css"> img { width: 100%; } </style> と出力されます。 Reference マークアッパー的 Slim 入門21の手引き | e2esound.com業務日誌

How to use new wercker to deploy to Heroku

日本語はこちら uchinoinu.hatenablog.jp What I want to do local --(git push origin master)--> bitbucket --> wercker --(passしたら)--> heroku Problems wercker is difficult to use for me Recently, wercker is really changeable. Free plan is wo…

Bitbucketで管理しているRailsプロジェクトを新しくなったWerckerを通じてHerokuにデプロイしてみた

English Version is here uchinoinu.hatenablog.jp やりたいこと Bitbucketにpushしたら、werckerが動いて、パスしたら、Herokuにデプロイされる local --(git push origin master)--> bitbucket --> wercker --(passしたら)--> heroku 問題 Werckerが変わり…

In Rspec routing test code, add format to target url.

Memo require "rails_helper" RSpec.describe Api::V2::HogeController, type: :routing do describe "routing" do it "routes to #mine" do expect(:get => "/api/v2/hoges/mine").to route_to("api/v2/bookmarks#mine", format: "json") end . . .

When you want to use url with locale, OAuth using Devise &amp;amp; OmniAuth has error at callback. How to resolve?

Edit config/routes.rb, set only ominauth_callbacks outside of scope of locale. Rails.application.routes.draw do devise_for :users, skip: [ :session, :password, :registration, :confirmation ], controllers: { omniauth_callbacks: 'users/omnia…

StrongParameter でparameterに配列があるとき、その配列の中身をチェックする方法

paramsがこんな感じのとき { "foo": [ { "bar": "tar", "baz": "sar" }, { "bar": "tor", "baz": "sor" }, { "bar": "ter", "baz": "ser" }, { "bar": "tir", "baz": "sir" }, ] } StrongParametersで配列の中身を見る private def foo_params params.requir…

difference between namespace and scope at config/routes.rb

memo namespace namespace :api do get '/test' => 'tests#index' end => GET /api/test(.:format) api/tests#index scope scope :api do get '/test' => 'tests#index' end => GET /api/test(.:format) tests#index

422 error at creating User record in User Model using Devise

症状 RailsでJSON API用のバックエンド(管理画面はactive adminを利用し、そこだけはhtmlを利用)を作っています。 認証周りにDeviseを利用しました。 Routingは↓な感じで。 # config/routes.rb namespace :api, format: 'json' do namespace :v1 do devise…

401 when access to /admin with JSON-API backend by Rails

症状 何事も無ければ、active_adminを使っている場合、/adminにアクセスしたら、以下の様な画面が見れるはずです。 しかし、今回こんな感じになりました。 Started GET "/admin" for ::1 at 2015-05-12 18:06:23 +0900 Processing by Admin::DashboardContro…

Crafting Rails 4 Applications - capter 1-5 - Wrapping Up

こちらの記事の続きです。 Crafting Rails 4 Applications - capter 1-4 - Talking It to the Next Level - Satomi's Daily Notestsumekoara.hateblo.jp 1.5 まとめ この章ではPDFフォーマット用のrendererを作りました。このアイデアを使えば、csvやatomと…

Crafting Rails 4 Applications - capter 1-4 - Talking It to the Next Level

こちらの記事の続きです。 Crafting Rails 4 Applications - capter 1-3 - Understanding the Rails Rendering Stack - Satomi's Daily Notestsumekoara.hateblo.jp 1.4 次のレベルへ rendererの実装に話を戻します。以下の様なcontrollerでないが起きるか勉…

Crafting Rails 4 Applications - capter 1-3 - Understanding the Rails Rendering Stack

こちらの続きです。 Crafting Rails 4 Applications - capter 1-2 - Writing the Renderer - Satomi's Daily Notestsumekoara.hateblo.jp 1-3. Rails Rendering Stackを理解する Action MailerとAction Controller はいくつかの共通機能を持っています。例え…

Crafting Rails 4 Applications - capter 1-2 - Writing the Renderer

↓のつづきです。 Crafting Rails 4 Applications - capter 1-1 - Satomi's Daily Notestsumekoara.hateblo.jp 1.2 Rendererを書く まずはじめに、render()メソッドと許容されるいくつかのオプションについて話をしましょう。rendererとは何かということを正…

annotate gem: write schema or routing on model file, routes file

(source: http://whyzat.com/wp-content/uploads/2014/04/Useful-Dog.jpg) Version Ruby # 2.2.1 Rails # 4.2.0 Install $ vi Gemfile -------- # add gem 'annotate' -------- $ bundle install Make Config File(Task File) $ bundle exec rails g annotat…

Screen-capture with wkhtmltoimage(wkhtmltopdf) onLinux

In many cases, phantom.js is used to get screen capture. But wkhtmltoimage can be alternative. Install http://wkhtmltopdf.org/downloads.html $ sudo yum install -y openssl libX11 libXext libXext.so.6 $ cd /usr/local/src $ wget http://downlo…

try update_all as bulk update like bulk insert

to use bulk insert on Rails, add gem below. gem 'activerecord-import' In MySQL, bulk update can be used by this gem, but postgres..... sqlite..... update_all solution! # make all records with open: false to open: true Shop.where(open: fals…

Devise 3.x, Rails4.x で create時に、ActionController::UnknownFormat in Devise::RegistrationsController#new が出るとき

Deviseを使ってユーザー登録を使用としたら、Devise::RegistrationsControllerの方のrespond_withのあたりでActionController::UnknownFormatエラーが吐かれました。 ルーティングはこんな感じ devise_for :users, :controllers => { :sessions => "users/se…

Rails4.x で simple_formを使って、create(登録)とupdate(編集)で同じformを使う際の注意

simple_formを使っています。 同じformを使ってcreateとupdateをすることが多いと思います。 症状 updateを叩いたつもりが、こんなエラーに出くわしました。 Routing Error No route matches [PATCH] “/hoge" ちなみにroutingは POST /hoge(.:format) hoge#c…

Using Elasticsearch on Yosemite and Heroku at Rails4.2 Project

Install elasticsearch to Yosemite! Yosemite $ brew install elasticsearch # Elasticsearch Client gem 'elasticsearch-model' gem 'elasticsearch-rails' gem 'bonsai-elasticsearch-rails' $ bundle install Plugin Japanese Character Adaptor The Jap…

Mac Yosemite に RMagick を入れてみました

Rails4で作っているプロジェクトで、Carrierwaveを使おうとすると、RMagickも一緒に使うことが多いかと思います。 それらのセットアップ時のトラブルです。 エラーたち bundle installが落ちる $ bundle install --path vendor/bundle ---- An error occurre…

MacOSX YosemiteでRails4.xを動かして、Postgresと繋げるときのメモ

Rails4.2で作っていたプロジェクトをHerokuで運用していくことになりました。 しかし、さくらvpsやAWSを想定していたこともあり、慣れたMySQLをこれまで使っていました。 そこでMySQLからPostgresへ移し替えることになりまして、その際起きたトラブルのメモ…

rails-templateを作ってみた

こちらを参考ししました。 Ruby - RailsのApplication templateを使って開発の初速をあげよう! - Qiitaqiita.com まだコピペしては継ぎ接ぎしたり、試行錯誤中なので、 これから改善していきます。 http://techracho.bpsinc.jp/baba/2012_06_27/5811 tsumek…

プロジェクト名を変更する場合

Rails4.1系のプロジェクト名を変更する際のメモです。 手動 以下の二箇所で大丈夫そうです。。。。 config/application.rb config/initializers/session_store.rb module ProjectName end Rails.application.config.session_store :cookie_store, key: '_pro…