github.com/dnephin/dobi@v0.15.0/examples/init-db-with-rails/app/setup.sh (about)

     1  #!/bin/bash
     2  #
     3  # Automate the steps of the rails getting started guide
     4  #
     5  set -eu
     6  
     7  rails new blog
     8  cd blog
     9  bin/rails generate controller Welcome index
    10  
    11  cat > config/routes.rb <<EOF
    12  Rails.application.routes.draw do
    13  
    14    resources :articles
    15  
    16    root 'welcome#index'
    17  end
    18  EOF
    19  
    20  bin/rails generate controller Articles
    21  cat > app/controllers/articles_controller.rb <<EOF
    22  class ArticlesController < ApplicationController
    23    def new
    24    end
    25  
    26    def create
    27      @article = Article.new(article_params)
    28  
    29      @article.save
    30      redirect_to @article
    31    end
    32  
    33    private
    34      def article_params
    35        params.require(:article).permit(:title, :text)
    36      end
    37  end
    38  EOF
    39  
    40  cat > app/views/articles/new.html.erb <<EOF
    41  <%= form_for :article, url: articles_path do |f| %>
    42    <p>
    43      <%= f.label :title %><br>
    44      <%= f.text_field :title %>
    45    </p>
    46  
    47    <p>
    48      <%= f.label :text %><br>
    49      <%= f.text_area :text %>
    50    </p>
    51  
    52    <p>
    53      <%= f.submit %>
    54    </p>
    55  <% end %>
    56  EOF
    57  
    58  bin/rails generate model Article title:string text:text
    59  
    60  # TODO: set these to different values
    61  cat > config/database.yml <<EOF
    62  development:
    63    adapter: postgresql
    64    database: postgres
    65    host: postgres
    66    user: postgres
    67  EOF
    68  
    69  echo "gem 'pg', '~> 0.18.0'" >> ./Gemfile
    70  bundle install