When the user login is completed, all the posted contents will be displayed on the top page.
Although it is a function, I want to display the edit button and the delete button together.
Corresponding source code
NameError in Homes # index Showing /Users/taigasoma/projects/meiwa/app/views/homes/index.html.erb where line # 6 raised: undefined local variable or method `home'for #<#<Class: 0x00007f931c445c08>: 0x00007f931c4442b8> Did you mean? @homes
<% = render "shared/header"%> <% if user_signed_in?%> <ul> <li> <% = link_to'Edit product', edit_home_path (home.id), method:: get, class: "home-red-btn"%> </li> <li> <% = link_to'Delete', home_path (home.id), method:: delete, class:'home-destroy'%> </li> </ul> Omitted below
Rails.application.routes.draw do devise_for: users root to:'homes # index' resources: homes do end end
class HomesController</pre> <strong>What I tried</strong> <p>This time, it is not a transition to show action, so add index to before_action<br /> Error occurred</p> <pre><code data-language = "error">couldn't find home without an id
It seems that home.id is not entered properly.
If i have any advice, thank you.
After rewriting with
NoMethodError in Homes # index Showing /Users/taigasoma/projects/meiwa/app/views/homes/index.html.erb where line # 6 raised: undefined method `id'for nil: NilClass
This error has occurred.
Answer # 1
If the controller method refers to the same view, if one is executed, the other will not be executed, so the variable that is not executed is not passed to the view = nil.
I think that will be the case.
Depending on the requirements, such as sending the initial value for some reason or changing the view.
Answer # 2
<% = render "shared/header"%> <% if user_signed_in?%> <p> <% = link_to'Edit product', edit_home_path (home.id), method:: get, class: "home-red-btn"%> </p> <p> <% = link_to'Delete', home_path (home.id), method:: delete, class:'home-destroy'%> </p> <% @ homes.each do | home |%> <% = home.buildingname%> <% = image_tag home.images , class: "home-box-img"%> <table> <tbody> Omitted below
In the omitted part, I wrote the code in each and sent the home information.
So, put in each.
Omitted above </table> <p> <% = link_to'Edit product', edit_home_path (home.id), method:: get, class: "home-red-btn"%> </p> <p> <% = link_to'Delete', home_path (home.id), method:: delete, class:'home-destroy'%> </p> <% end%> <% end%> <% = render "shared/footer"%>
I was able to display it here.
Thanks to the advice of those who commented.
Thank you very much.
- ruby on rails 6 - the delete function cannot be implemented well
- ruby - i want to display sold out
- ruby - i want to display lowercase hexadecimal letters in uppercase
- ruby on rails - i want to display the posted images in a random order (get information from the record)
- ruby - i want to display the alphabet in capital letters when displaying in hexadecimal
- ruby - if there is a job waiting in sidekiq, i want to display that it is being processed in rails view
- ruby - i want to display specific columns in rails in descending order of numbers
- ruby - i want to display the name of the poster
- ruby - sprockets :: rails :: helper :: assetnotfound in posts # index i want to display the images saved in my computer
- ruby - when deleting a post, i want to delete the comment associated with the model together
- ruby - i want to display monthly data in one
- python - i want to display the my page button only to users who have logged in with django, but there is a problem
- java - i want to delete a line with a radio button
- ruby - i'd like to implement a genre-specific display function in [rails], but i'm having trouble as i expected
- ruby on rails 6 - i want to change the display of the product detail page according to the user's conditions
- ruby on rails - [rails] how to round (omission and display) the character string of link_to
- java - i want to display a pop-up with a text copy button in ajax communication (response from the server)
- ruby on rails - i want to display all the images in the [rails] directory in the browser!
- ruby - i want to display only the image of the logged-in user when executing the search function
- ruby - [rails6] i get an error on heroku when i write
- ruby - i want to display new posts i made on the top page only for myself
- ruby - link_to method:: post doesn't work
- ruby - about rails routing
- ruby - how to pass the "password" on the wizard screen
- ruby - dealing with validation errors when rendering rails apps (definition of instance variables)
- ruby - n + 1 problem in api mode
- ruby - how to give edit permissions only to rails contributors