【Railsで学生野球連盟のHP作成】開発記録002 新着情報テーブル作成
・新着情報投稿画面
・新着情報編集画面
・新着情報詳細画面
・新着情報一覧画面
→scaffold
→アセットの自動生成を制御(scaffold.css.scssだったっけ?前作ったサービスの時、bootstrapと競合してデザイン苦戦したので今回は自動生成を抑えてみる)
config/application.rb
module AppName
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
# アセットの自動生成を制御
config.generators do |g|
g.assets false
end
end
end
・トップぺージ
→新着情報を最新順に5件取得して表示
app/controllers/top_controller.rb
class TopController < ApplicationController
def show
@infos = Info.limit(5).order(created_at: :DESC)
end
end
<参考>
ていうかコードコピペしたらエディタの見た目でペーストされたんですけど…。
今までcommand+shift+vしてたから気づかなかった…。はてなブログすげえ。