프로그래밍/Rails 4

Rails App에 Bootstrap 사용하기

versions Rails 5.1이상 Bootstrap 4 이상 Gemfile Gemfile에 bootstrap과 의존관계인 jQuery를 설치 gem 'bootstrap' gem 'jquery-rails'$ bundle installapplication.scss Rails App 작성 시에 생성되는 application.css를 application.scss로 rename해준다. $ mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss생성된 application.scss에 기존 코드를 삭제 후 bootstrap을 import하기 @import "bootstrap";scss파일에서 i..

_path와 _url의 차이

Rails route를 작성하면 controller에서 사용할 수 있는 헬퍼의 일종인 _path와 _url의 차이를 알아보자. _path 상대패스 redirect_to 외에서 사용 link_to에서 많이 사용 root_path => '/' new_path => '/new' _url 절대패스 redirect_to에서 많이 사용(HTTP에서는 리다이렉트할 때 완전한 URL을 요구하므로) root_url => 'http://www.example.com/' new_url => 'http://www.example.com/new'

Rspec 기초

describe/ it / expect describe(RSpec.describe)는 테스트의 그룹화를 선언 번역하면 ~을 기술한다. ~을 설명한다 등의 의미 it은 테스트를 example단위로 정리하는 역할 it do ... end의 expectation이 모두 패스하면 그 example은 통과됨 expect(X).to eq Y처럼 기대값과 실제값을 비교함을 기술하는 것이 expectation. Nested describe describe는 describe안에 몇개든 네스트되어 사용할 수 있다. 기본적인 역할은 테스트의 그룹화 이므로 적절히 그룹화한다면 테스트가 어떤 기능을 테스트하는지 알기 쉽게 기술할 수 있다. context and before RSpec에는 describe이외에도 context라는..

Rails에 Rspec, Factory_bot 설정하기

Rails의 테스트 코드를 작성하기 위해 Rspec과 Factory_bot을 설치, 설정하는 과정을 메모 Ruby, Rails버전 $ ruby -v ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19] $ rails -v Rails 6.0.3.4 설치순서 Gem Install Gemfile에 Rails용 Rspec,Factory_bot을 추가한 후 bundle install로 설치 group :development, :test do gem 'rspec-rails' gem 'factory_bot_rails' end Rspec설정 Rails의 generate커맨드로 rspec에 필요한 파일 생성 $ bundle ex..