[RUBY] [rails] How to display db information

Thing you want to do Extract all the information in the Item table Display database information in view file index.html.erb

Premise Item table contents info column! I want to display the saved contents in the info column

① Described in items_controller

 def index
    @items = Item.all
  end

Commentary

When the index action moves Make @items contain all the information in the Item table.

② Describe in index.html.erb file

<% @items.each do |item| %>
<%= item.info%>
<%end%>

Commentary

<% @items.each do |item| %> @items ← Item table Contains all the information. Extract all the information from there and assign it to item (variable) one by one. <%= item.info%> Information saved in the info column <%= %> Information can be displayed by adding equality

Contents of Item table info Explanation 1 Explanation 2

View of index.html.erb Explanation 1 Explanation 2 (The information saved in the info column is displayed)

Recommended Posts

[rails] How to display db information
[Rails] How to display information stored in the database in view
[Rails] How to display error messages individually
[Rails] How to use video_tag to display videos
How to write Rails
How to uninstall Rails
[rails] How to display parent information in child view in nested relationships
[Ruby on Rails] How to display error messages
[Rails MySQL] How to reset DB on heroku
[Rails] How to convert UC time display to Japanese time display
[rails] How to post images
[Rails] How to use enum
[Rails] How to install devise
[Rails] How to use enum
How to read rails routes
[Java] How to display Wingdings
How to use rails join
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
How to set the display time to Japan time in Rails
[Rails, JS] How to implement asynchronous display of comments
[Ruby On Rails] How to reset DB in Heroku
[Rails] How to display an image in the view
[Rails] How to install Font Awesome
[Rails] How to use devise (Note)
[Rails] How to write in Japanese
[Rails] How to prevent screen transition
How to use Ruby on Rails
How to deploy Bootstrap on Rails
[Rails] How to speed up docker-compose
[Rails] How to add new pages
Rails on Tiles (how to write)
[Rails] How to write exception handling?
How to specify db when creating an app with rails
[Rails] How to install ImageMagick (RMajick)
How to display a graph in Ruby on Rails (LazyHighChart)
[Rails] How to install Font Awesome
[Rails] How to use Active Storage
How to introduce jQuery in Rails 6
[Rails] How to display the list of posts by category
[Rails] How to implement star rating
How to return Rails API mode to Rails
How to get along with Rails
Rails DB PostgreSQL changed to MySQL
[Introduction to Rails] How to use render
[Rails] Reflection to db using seeds.rb
[Rails] How to display error messages for comment function (for beginners)
How to install Swiper in Rails
[Rails] How to execute "rails db: create" etc. in production environment EC2
[Rails / Heroku / MySQL] How to reset the DB of Rails application on Heroku