Last active
August 11, 2020 09:59
-
-
Save tokhi/12fe81b6eee1325d6845 to your computer and use it in GitHub Desktop.
Some useful rails command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adding a column to an existing table | |
rails g migration AddNameToUsers name:string | |
# or | |
rails generate migration add_image_to_pictures image_id:string | |
# to remove | |
rails d migration AddNameToUsers name:string | |
# remove column from model | |
rails g migration RemoveProjectIDFromProjects project_id:string | |
# install rspec | |
bin/rails g rspec:install | |
# has_many association | |
rails g scaffold Comment post:references | |
# hash many association to more models | |
rails g scaffold Favorite post:references user:references | |
# generate the project first | |
rails g model Task description:string done:boolean project:belongs_to | |
# annotate ~> annotate | |
# install devise | |
rails g devise:install | |
rails g devise User | |
# generate model | |
rails g model Picture image:string | |
# see all the generate options | |
rails generate -h | |
# creating a scaffold controller for an existing model | |
rails g scaffold User name --skip | |
#or rails g scaffold_controller User | |
# creating a scaffold model | |
rails generate scaffold Book title:string author:string | |
# restaurant and user has_and_belongs_to_many relationship. | |
rails g migration create_restaurants_users | |
#Using resource Instead of using the scaffold generator; | |
#resource generator will not generate all the files and methods created by the scaffold generator. | |
rails g resource Record title date:date amount:float | |
# drop and up a specific migration | |
rake db:migrate:redo VERSION=my_version | |
# or | |
rake db:migrate:down VERSION=20160111162227 | |
rake db:migrate:up VERSION=20160111162227 | |
# search by association | |
Account.joins(:trades).group('accounts.id').having('count(account_id) >2') | |
# rspec api mock | |
https://www.honeybadger.io/blog/ruby-external-api-test/ | |
#__________________ | |
# select box from a hash | |
<%= select_tag('lead[order_type]', options_from_collection_for_select(@states_list["dachdecker"]["order_type"], :first, :last), options = {prompt: "Bitte wählen"}) %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment