技術系ブログ

とにかく小ネタで

2019-10-01から1ヶ月間の記事一覧

【Rspec】RSpec+CapybaraでBootstrap のドロップダウンをテスト

例 _header.html.slim li.nav-item.dropdown a.nav-link.dropdown-toggle herf="#" role="button"data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" i.fas.fa-smile.mr-2 | #{@user.name} 上記のようなドロップダウンがあった場合、 click…

【Rspec】Capybara::Ambiguous: Ambiguous match, found 2 elements matching visible link

Rspec中にタイトルのようなエラーが出た場合,match: :firstで解決する 実例 it "説明ページに遷移" do click_link "お絵かきBOXとは",match: :first expect(current_path).to eq pages_about_path end 一画面にお絵かきBOXとはというリンクボタンが2つある…

【rails】かんたんログイン機能導入方法

参考:【学習アウトプット2】離脱率を下げる!かんたんログイン機能の実装 - Qiita 現在railsでポートフォリを作成中ですが、よりスムーズに使ってほしいためにこの機能を導入したくなったので作りました。 若干手抜き感が否めないですが、一応使えます。 こ…

【rails】いいね機能実装 (追記あり)

参考:【Rails】いいね機能の実装手順 | たみずブログ 現在railsアプリを製作中です。いいねの実装ができたので残しておきます。 Likeテーブルを導入 ルーティングの設定 viewの作成 コントローラー側 Postsコントローラの設定 view側 部分テンプレート 追記 …

【つまずいた】scssに書いたのに反映されない

結論、気づかずに子要素として書いてしまっていた 例 .header{ 気づかずにこの辺に書いてた .footer{ } } 書いている本人は .header{ } .footer{ } このように書いているつもりでしたが、間違えてました。 次、同じミスをしたいために VScodeで保存時に自動…

【css】footerバーをページ下部に固定

html.slim .footer ul li とあると css側に .footer{ position: absolute; bottom: 0; } これだけだった。忘れてた

【rails】fontawesome使い方

Font Awesome まずgem 'font-awesome-sass'を導入してbundle 次にapplication.scss内に @import 'font-awesome-sprockets'; @import 'font-awesome'; をインポート これにより使えるよになります。 link_to編 = link_to root_path i.fas.fa-home | トップペ…

【rails】リンクに画像をつける場合

例 画像の保存先 /assets/images/icon.png = link_to image_tag("/assets/icon.png"),root_path または、= link_to image_tag("icon.png"),root_path で表示される 参考 https://techacademy.jp/magazine/22197 こんだけ また、 Railsで扱う画像はassetsとpu…

【Rspec】image_dataを含むモデルのFactoryの作り方

色々試したけども実際にターミナルに出てきたimage_dataをコピペした。 FactoryBot.define do factory :post do content { "MyString" } image_data {"{\"original\":{\"id\":\"da82368d07ad508f3955c85918af11c0\",\"storage\":\"store\",\"metadata\":{\"f…

【Rspec】undefined method `sign_in' エラー対処法

deviseをRspecでテストしているときにタイトルのようなエラーが出たので 解決策 spec/rails_helper.rb RSpec.configure do |config| config.include Devise::Test::ControllerHelpers, type: :controller #この一行を追加する end 参考: 【Rails4】Devise::M…

FactoryBotのassociation方法

rspecでモデルのテストを書いているのだかassociationしているpost modelについて書き方がわかったのでメモしておく。 モデル側 class User < ApplicationRecord has_many :posts end class Post < ApplicationRecord belongs_to :user end の場合 FactoryBo…

WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Sele nium::WebDriver::Chrome::Service#driver_path= instead.

文字通りUse Selenium::WebDriver::Chrome::Service#driver_path と書いてあるので group :text do - gem 'chromedriver-helper' + gem 'webdrivers' end これでエラーが出なくなります 参考: Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_p…

rspec注意点

context "ユーザーが有効な場合" do it "有効であること" do expect(@user).to be_valid end end スペースは半角でないとエラーが出る。 いつの間にか全角スペースになっていて気が付かなかった

Active Record バリデーション

参考: Active Record バリデーション - Rails ガイド バリテーションとは バリデーション (検証: validation)を使うことによって、正しいデータだけをデータベースに保存することができます よく使うバリデーションヘルパー ①acceptance:フォームが送信さ…

カラムのみ消す場合

例えばrails g model User name:string title:string content:text とmodelを作り rails db:migrateした ときに、nameのみ消したい場合 rails generate migration Removeカラム名Fromテーブル名 カラム名:データ型 例rails g migration RemoveNameFromUsers …

エイリアス設定

参考【初心者向け】エイリアスの設定方法 - Qiita 現在、railsアプリを製作中なのですが毎回、毎回rails sと書くのが面倒なんで エイリアスの設定をしたいと思います。 エイリアスとは、偽名、別名、通称などの意味を持つ英単語。 らしいです。別名ってとこ…

gitpushしてしまった.gitignore追加方法

.gitignoreにgithubに上げたくないファイル名を書く git rm --cached -r ファイル名 そして git push .gitignoreファイル書き方まとめ(よく使う編) uploadsディレクトリを無視する場合 /public/uploads 参考 [Git] .gitignoreの仕様詳解 - Qiita