I want to fill in "user information (name/introduction)" and "post form" in the html of the partial template and use it in index.html.erb that supports the "books" controller, but user information (name/introduction) I don't know how to reflect the introduction) well.
(name/introduction is registered as a column of User model)
How can the name and introduction be reflected in the following partial template that is currently being created? (The arrow is attached to the relevant part in the html of the template below)
Thanks for your guidance.
(If i have any questions about the contents of the explanation, we would appreciate it if you could ask a question.)
<table> <tr> <td><% = book.user.name%></td> </tr> <tr> <td>name</td> <td><% =%></td> ↑ Here </tr> <tr> <td>introduction</td> <td><% =%></td> ↑ Here </tr> </table> New book <% = form_with model: book, local: true do | f |%> Title <% = f.text_field: title%> Opinion <% = f.text_area: body%> <% = f.submit'Create Book'%> <% end%>
<% = render'layouts/list', book: Book.new%> Books <table> <thead> <tr> <th>Title</th> <th>Opinion</th> </tr> </header> <tbody> <% @ books.each do | book |%> <tr> <td><% = image_tag ('sample-author1.jpg')%></td> <td> <% = link_to book_path (book) do%> <% = book.title%> <% end%> </td> <td><% = book.body%></td> </tr> <% end%> </tbody> </table>
class BooksController nil end def update @book = Book.find (params [: id]) Book.update (book_params) redirect_to book_path (@book) end def destroy @book = Book.find (params [: id]) @ book.destroy redirect_to books_path end private def book_params params.require (: book) .permit (: title,: body) end end
Answer # 1
After adding "user: @user" to<% = render'layouts/list', book: @book%>, it was displayed when I entered "user.name" and "user.introduction" in the partial template. ..
Thank you to everyone who responded.
- ruby on rails - rails render: about the matter that the url after new is different
- ruby - [rails] about nameerror
- ruby on rails - about the description in applicationjs
- ruby on rails - about deploying apps using s3 function
- ruby on rails - variables are not passed to the partial template without reloading
- ruby - about routing using rails collection
- ruby - [rails] about the error that occurs when deleting likes (routing error)
- ruby on rails - about multi-word search to multiple columns using ransack
- ruby on rails - about image distribution on heroku and s3
- ruby on rails - about the matter that does not transition to the detail page
- ruby on rails - about conditional branching using elsif
- ruby on rails - about rails composite indexes
- ruby on rails - about primary key/natural key/surrogate key in db design
- ruby on rails - about nomethoderror in skilscontroller # create
- ruby - about rails routing
- ruby - about rails controller new action
- ruby on rails - about saving comments
- ruby on rails - about rails create action
- ruby on rails - [rails] about the problem that screen transition is not possible (error does not occur)
- ruby - passing variables using render partial
- ruby - deployment error on heroku
- ruby - output the total integer value held by each user
- ruby - i want to use the search method for active hash data
- ruby - destroy action does not respond
- ruby - how do you see the rails controller relative path? (carrierwave directory deleted)
- ruby - when deploying on capistrano, i get the error "access denied for user'ec2-user' @'localhost' (using password: no)&qu
- how to reflect the layout downloaded from the external site in ruby on rails?
- ruby - how nice! function routes do not pass well (relation) [rails]