Skip to content

Instantly share code, notes, and snippets.

@hack3rvaillant
Last active March 29, 2021 14:17
Show Gist options
  • Save hack3rvaillant/7945c5226aae24980a721f551d733587 to your computer and use it in GitHub Desktop.
Save hack3rvaillant/7945c5226aae24980a721f551d733587 to your computer and use it in GitHub Desktop.
rails template
devise_installed = false
if yes?('Do you want to install Devise ?')
# GEMFILE
gem 'devise'
run 'bundle install'
# Devise install
########################################
generate('devise:install')
inject_into_file 'app/views/layouts/application.html.erb', after: '<body>' do
<<-HTML.chomp
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
HTML
end
if yes?('Do you want to install french locales for Devise ?')
run 'curl https://gist.githubusercontent.com/leopirolo/b148850bcc1f7718a99d7f8b2b85ddbf/raw/c7b4205c39ba237987da3a887318c3e7bc27c846/devise.fr.yml > devise.fr.yml'
run 'mv devise.fr.yml config/locales'
end
environment 'config.action_mailer.default_url_options = { host: "http://localhost:3000" }', env: 'development'
production_url = ask("What is the production url of your project")
environment "config.action_mailer.default_url_options = { host: '#{production_url}' }", env: 'production'
devise_model_answer = ask('What\'s the name of the model you want to use with devise ? (default is User)')
devise_model = devise_model_answer == '' ? 'User' : devise_model_answer
generate('devise', devise_model)
run 'rails db:migrate'
inject_into_file 'app/controllers/application_controller.rb', after: 'class ApplicationController < ActionController::Base' do
<<-RUBY.chomp
before_action :authenticate_#{devise_model.downcase}!
RUBY
end
generate('devise:views') if yes?('Do you want to generate devise views ? P.S. you can still do it later...')
devise_installed = true
end
puts '🎉 Devise sucessfully installed' if devise_installed
if !File.exist?('app/controllers/pages_controller.rb') && yes?('Do you want to create a PagesController for static pages ?')
pages_names_response = ask('What pages do you want to create ? space separated')
pages_names = pages_names_response.split(' ').map(&:downcase)
generate(:controller, 'pages', *pages_names)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment