List display (index action)
New form (new action)
Click Create New (assuming you clicked Create New Cell on the right next to the top 646)
Describe the content in the form and submit the form
The newly created data will be in the cell to the right of 646
but it doesn't work.
class MainCowsController</pre> <p>index.html.erb</p> <pre><code data-language = "HTML"><% @page_title = "Milk management"%> <% = @page_title%> <% if @ maincow.present?%> <table class = "index" align = "left"> <% 20.downto (1) .to_a.each do | i |%> <% @cow = @ maincow.find_by line: i%> <% if @ cow.present?%> <tr><td><% = link_to @ cow.number, @cow%></td></tr> <% else%> <tr><td><% = link_to "Create new", new_main_cow_path%></td></tr> <% end%> <% end%> </table> <table class = "index" align = "left"> <% 40.downto (21) .to_a.each do | i |%> <% @cow = @ maincow.find_by line: i%> <% if @ cow.present?%> <tr><td><% = link_to @ cow.number, @cow%></td></tr> <% else%> <tr><td><% = link_to "Create new", new_main_cow_path%></td></tr> <% end%> <% end%> </table> <% end%>
<% @page_title = "Create new"%> <% = @page_title%> <% = form_for @maincow do | form |%> <% = render "form", form: form%><% = form.submit%> <% end%>
<table class = "form"> <tr> <th><% = form.label: number, "Individual identification number"%></th> <td><% = form.text_field: number, size: 8%></td> </tr> <tr> <th><% = form.label: name, "Name"%></th> <td><% = form.text_field: name, size: 50%></td> </tr> <tr> <th><% = form.label: birthday, "date of birth", for: "maincow_birthday_1i"%></th></th> <td><% = form.date_select: birthday, start_year: 2010, end_year: Time.current.year, use_month_numbers: true%></td> </tr> </table>
Migration script # 2
I think that the problem itself can be solved if you can enter a line column in the form.
After you click New, is set line column of the clicked cell is in the auto, in the form I want to to enter number column, name column, the only birthday column.
I think what a good way?
Answer # 1
How to identify cows is a mess.
If you look at migration, id, number, and line are likely to hit it. However, it is better not to use it for that purpose because it is not unique to cattle. For example, when you become 100 heads and display 20 heads per screen, it is troublesome.
If managed by number,
<% @cow = @ maincow.find_by line: i%>and not fetching from DB in view
@maincow = MainCow.order ("number")in controller index
<% 20.downto (1) .to_a.each do | i |%> <% @cow = @ maincow.find_by line: i%>
<% @ maincow.each do | cow |%>
<% end%> <% = link_to cow.number, cow%> <% = link_to "Create new", new_main_cow_path%>
However, since there is no one at the beginning, the top 20 lines are empty and only the last new creation is made.
- html - about position: absolute;
- about the phenomenon that the [id] set in rails collection_select changes on the html side
- html - about parent-child element relationship
- html - bootstrap card about the height of the bootstrap card
- i have a question about html css
- html - about width specification to check with developer tools
- ruby - about notation of create action
- html - about duplication of click () event in jquery
- html - about adjustment problem of icon image + balloon
- html - about changing the font color of css
- html - [ruby on rails] about the problem that line breaks are not reflected in the text data acquired by innertext of mechanize
- html - about vendor prefixes after the recommendation stage
- about scroll display when overflowing html elements
- html - please tell me about the layout of the navigation bar of bootstrap4
- html - about the part where mix-blend-mode is not reflected
- [html] about specifying height in responsive design
- html - about the work of multiple people
- java - i have a question about new
- html - about chrome verification tool
- about html bem
- html - i want to set the conditions to be displayed in collection_check_boxes
- html - i would like to know how to calculate the average of the data
- ruby - i want to be able to see "liked posts" by the person on the rails development user detail page
- [ruby] how to write a ternary operator
- ruby - i want to pass an instance variable and display a post, but i get a nomethoderror
- ruby - how to delete cookies
- ruby - i want to get records that match multiple foreign keys from within an intermediate table