I want to solve NoMethodError to get&reflect the demo data described in db!
Write the source code of db and in the corresponding directory (blog-app-hirochan) in the terminal
$rails db: seed
Has been executed.
▼ Problem occurring (details of the phenomenon occurring/error message/screenshot)
I have a screenshot.
▼ Source code, log
https://github.com/hirooutdoor/blog-app-hirochan/tree/show-articles
▼ What I tried to solve the problem
Since it was'each'for nil: Nilclass, I suspected that @articles could not be defined properly.
▼ I tried the following and thought about the problem (debugging result)
(1) Confirm that the description of app/views/index.html.erb with the relevant part seems to be correct.
List of new articles
Timeline
<% @ articles.each do | article |%>
<% = image_tag'eyecatch1.png'%>
<% = article.title%>
<% = image_tag'heart.svg'%>
<span>23</span>
<% = image_tag'default-avatar.png'%>
<p>cohki0305</p>
<p>2020/4/16</p>
<% end%>
(2) Confirm that it can be defined in app/controllers/articles_controller.rb
class ArticlesController</pre>
<p><br />
③ Confirm that the description is as shown in the demo in app/db/seeds.rb</p>
<pre><code>Article.create ({title:'Visioning Power 1', content:' Almost all successful people are doing visioning. The brain can't tell what actually happened from what it imagined. Use this power to get an image of your success anyway.'})
Article.create ({title:'Visioning Power 2', content:'Put a photo of a great man all over the wall. You can check every day if i am approaching that person.'})
④ Confirm that the file of app/model/article.rb is correct.
class Article
Since it was'each'for nil: Nilclass, I suspected that @articles could not be defined properly, but it seems that it can be defined and what is the problem is clear. I would appreciate it if you could teach me>
-Addition-
I confirmed that the seed data can be generated by model using rails console.
Usage environment
Rails 6.0.3.4
VScode 1.49.2
-
Answer # 1
Related articles
- ruby on rails - i'm having trouble getting an actionview :: syntaxerror while implementing category selection using active_hash
- ruby on rails - i'm having trouble solving the test error
- ruby - [rails] i'm having trouble saving a table with the create action
- [ruby] i'm having trouble with nomethoderror
- ruby on rails - i'm having trouble downloading homebrew to my mac
- ruby on rails - nomethoderror has occurred in the permit part of the strong parameter, and the cause and solution are unknown
- i want to solve an error on the ruby on rails ec site nomethoderror in cartscontroller # add_item
- ruby on rails 6 - [error] nomethoderror in communities # index undefined method `following?'for nil: nilclass
- ruby on rails - rails6 rspec model run-time error nomethoderror: undefined method `valid?'for nil: nilclass
- ruby on rails 6 - [error] nomethoderror in followscontroller # create undefined method `follows' for nil: nilclass
- ruby on rails - nomethoderror in skils # new
- ruby on rails - nomethoderror in itemscontroller # new error
- ruby on rails: nomethoderror that occurred when adding a good function
- ruby on rails: about nomethoderror that occurred when adding a good function
- ruby on rails - nomethoderror in mypage # profile undefined method `username’ for nil: nilclass
- i'm having trouble with ruby's word bingo algorithm
- ruby - i'm having trouble getting a bcrypt-encrypted password in rails
- ruby - i'm having trouble solving the missing required keys: [: id] error
- ruby on rails 6 - [error] nomethoderror in communitiescontroller # create undefined method `published?'for # <community: 0x0
- ruby - the last db setting doesn't work when deploying rails app on aws
- ruby - i added a rails column, but i can't associate it with the user table
- ruby - after new registration with devise, an error is displayed
- ruby - i want to make a graph of the values retrieved by the each statement with chart kick
- ruby - i want to output all values at the beginning in the list search
- ruby - resolve rspec mysql foreignkey error
- ruby - rails comment function display
- ruby - i'm having trouble solving the missing required keys: [: id] error
- [ruby on rails 6] i implemented the tag function using acts-as-taggable-on, but i can't jump to the linked article from the list
Clone the questioner's repository
show-articles
I tried to run the branch of.I was able to display it without any problems.
Maybe
rails db: seed
May not be working.Please check the contents of the database.
$sqlite3
If all goes well, you should see the contents of db: seed as above