I want to link to the edit page from the edit button in the profile field that is always displayed, but No Method Error occurs.
I know that there is no user_id, but I don't know how to fix it.
NoMethodError in Books # index Showing /home/ec2-user/environment/bookers-level2.herokuapp/app/views/books/index.html.erb where line # 21 raised: undefined method `user_id 'for nil: NilClass Extracted source (around line # 21): 19</table> 20 21<% = link_to edit_user_path (@ user.user_id), class: "btn btn-default" do%> 22<i></i> 23<% end%> 24<p>New book</p>
The following code is likely to be needed.
<% = render 'shared/header'%> <p>User info</p> <% = attachment_image_tag @user,: profile_image_id,: fill, 250, 250, format: 'jpeg', fallback: "no_image.jpg", size: '250x250'%> <table> <tr> <Th>name</th> <Th><% = current_user.name%></th> </Tr> <Tr> <Th>introduction</th> <Th><% = current_user.introduction%></th> </Tr> </table> <% = link_to edit_user_path (@ user.user_id), class: "btn btn-default" do%> <i></i> <% end%> <p>New book</p> <% = form_for (@book, url: '/ users') do | f |%> <p>Title</p> <% = f.text_field: title%> <p>Opinion</p> <% = f.text_area: body%> <% = f.submit 'Create Book'%> <% end%> <p>Books</p> <table> <thead> <tr> <th>Profile image</th> <th>Title</th> <th>Opinion</th> </tr> </thead> <% @ books.each do | book |%> <tbody> <tr> <td></td> <td><% = book.title%></td> <td><% = book.body%></td> </tr> </tbody> <% end%> </table> <% = render 'shared/footer'%>
Please let us know if there are any other missing points.
Answer # 1
link_to edit_user_path (@user)
It was possible to solve as.
If edit_user_path had params (id), it seemed to be necessary to pass a variable with id to the argument.
Answer # 2
I understand that there is no user_id
No, this is an error because
nil. I don't know how
Set exactly so that
Move even ifEither
will be supported.
- ruby on rails: nomethoderror that occurred when adding a good function
- ruby - i'm having trouble with rails nomethoderror (i want to get data with each method!)
- ruby on rails - nomethoderror in itemscontroller # new error
- ruby on rails - nomethoderror solution
- 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
- ruby on rails - nomethoderror has occurred in the permit part of the strong parameter, and the cause and solution are unknown
- ruby on rails - i can't delete rails comments nomethoderror in bookcommentscontroller#destroy
- ruby on rails - rails6 rspec model run-time error nomethoderror: undefined method `valid?'for nil: nilclass
- ruby - rails:loaderror occurs after rails s
- ruby on rails - nomethoderror in skils # new
- ruby on rails - rails nomethoderror in users#show solution
- ruby - nomethoderror occurs in create action
- ruby on rails - rails rspec argumenterror occurs when the mock under test has arguments
- ruby on rails - about nomethoderror in skilscontroller # create
- i want to solve an error on the ruby on rails ec site nomethoderror in cartscontroller # add_item
- you can do redirect_to with ruby on rails, but you get nomethoderror when rendering
- ruby on rails - the capacity shortage of cloud 9 and ec2 cannot be solved
- the ruby on rails each method does not repeat well
- ruby on rails - rails intermediate table save
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- python 3x - typeerror: 'method' object is not subscriptable
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - unresolved reference comes out in kotlin