🔺
Rails
  • Rails Wiki
  • Ruby
    • Ruby Basic Loop
    • Ruby Basic Method
    • Fizz Buzz on Rails
  • Rails Note
    • DBの形式変換Rais6
    • Rails開発環境
      • Rails on Docker 導入フロー
    • 2022 Re:Rails
    • Hello Rails
      • Genarate Controllr
      • Create Action
  • Zero One [QA Service]
    • QA-Servrice Index
    • Setting
    • Crate Model Base
    • Add Bootstrap/FontAwesome
    • Save Model on Save
  • Rails Vue
    • Add Vue on Rails
GitBook提供
このページ内

役に立ちましたか?

  1. Zero One [QA Service]

Crate Model Base

Model Base

app/controllers/questions_controller.rb

class QuestionsController < ApplicationController
  def index
    @questions = Question.all
  end
  ...

qustions/index.html.erb

<h2>Questions</h2>

<div class="row">
  <div class="col-md-12">
    <table class="table-responsive striped">
      <thead class="thad-light">
        <tr>
          <th>ID</th>
          <th>Title</th>
          <th>Menu</th>
        </tr>
      </thead>
      <tbody>
      <% @questions.each do |question| %>
        <tr>
          <td><% question.id %></td>
          <td><% question.title %></td>
          <td>[Edit] [Delete]</td>
        </tr>
      <% end %>
      </tbody>
    </table>
  </div>
</div>

rails db:seed

rails c

Question.all

irb(main):001:0> Question.all
   (1.0ms)  SELECT sqlite_version(*)
  Question Load (0.4ms)  SELECT "questions".* FROM "questions" /* loading for inspect */ LIMIT ?  [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Question id: 1, name: "Test Name 1", title: "Test Title 1", content: "Test content 1", created_at: "2021-04-09 06:25:13.084416000 +0000", updated_at: "2021-04-09 06:25:13.084416000 +0000">, #<Question id: 2, name: "Test Name 2", title: "Test Title 2", content: "Test content 2", created_at: "2021-04-09 06:25:13.093168000 +0000", updated_at: "2021-04-09 06:25:13.093168000 +0000">, #<Question id: 3, name: "Test Name 3", title: "Test Title 3", content: "Test content 3", created_at: "2021-04-09 06:25:13.097390000 +0000", updated_at: "2021-04-09 06:25:13.097390000 +0000">]>
前へSetting次へAdd Bootstrap/FontAwesome

最終更新 2 年前

役に立ちましたか?