1
0

More than 3 years have passed since last update.

[Rails]コマンドで作る★3分BBS

Last updated at Posted at 2020-04-16

Railsの復習がてらBBS作成の備忘録です。
今回初めてmysqlではなくscaffoldを使用するので
機能拡充しましたら随時更新予定です。

作成

ターミナル
$ rails new bbs
$ cd bbs

BBS作成

ターミナル
$ rails g scaffold テーブル名(例:articles) カラム名(:content):string #カラムの型(今回はtext入れるのでstring)
$ rails db migrate

index作成と表示〜BBSのlinkを貼るところまで

ターミナル
#コントローラーを作成
$ rails g controller ディレクトリ名(例:home index
config/routes
Rails.application.routes.draw do
  get 'home/index'
  resources :articles
  root "home#index" #追記した箇所
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
views/home/index.heml.erb
<h1>Welcome BBS</h1>
<p><%= Date.today %></p>  #今日の日付rubyの表示の仕方なので<%%>で囲ってます
<p>( ´▽`)</p>
<%= link_to "Show list",articles_path %> #パスは$rake routesで調べられます

備考:erbは埋め込むという意味らしい。

表示してみる

ターミナル
$ rails s

Webでlocal hostに接続してみてください
表示されるかと思います。

一旦ここまでで完成★

bbs-compressor.gif

参考ページ

Paizaラーニング
rails sとrails server -b 0.0.0.0の違い
動画を圧縮して軽くするサイト

終わりに

今まで見ていたテキストと別のテキストを見て復習をしています。
local hostの作成方法やアプリの新規作成の方法などが若干違っているので
テキスト進めつつ、更新も行なっていけたらなと思います。
cssつけてないので味気ないですが、実装自体は一瞬で終わります。笑

初学者のため不備のご指摘やアドバイスをいただけ得れば幸いです。
最後まで読んでいただきありがとうございます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0