[RUBY-ON-RAILS] 버튼은 다시로드 한 후 작동 양식 제출
RUBY-ON-RAILS버튼은 다시로드 한 후 작동 양식 제출
나는 테이블을 구축 인덱스 페이지를 가지고 있고, 나는 테이블에서 편집 라인의 사용자를 할 수 있도록 노력하고 있습니다. 레일을 공급하지 않는 한, 자바 스크립트, AJAX 등 - 나는 가능한 가장 기본적인 방법으로이 작업을 수행하려합니다.
내 표는 인덱스 방법에 벌금을 표시해야하고, 새 행을 추가하는 데 사용할 수있는 테이블의 마지막 행으로 형태가있다. 새로운 양식은 잘 작동합니다. 각 행은 컨트롤러의 편집 방법과 경로가 편집 링크가 있습니다. 제어기는 편집 할 대상을 설정하고, 인덱스, 편집 할 수있는 행의 형태로이 시간을 렌더링한다. 내 문제는이 양식을 제출하지 것입니다,하지만 난 페이지를 새로 경우는 제출합니다.
페이지를 새로 고침 후 제출 사실은 매우 혼란. 나는 (? 여전히 잘 같은 변수와 같은 라우팅을 통해 이동합니다) 새로 고침는 다음 링크를 클릭하면 아무것도 다른 할 것이라고 표시되지 않습니다 내가 전에 새로 고침 후 양식 HTML의 차이를 볼 수 없습니다 . 어떤 일이 일어나고가 무엇인지에 대한 아이디어가?
난 간다에서 찾기 시작,하지만 코드를 확실하지 않다;
index.html.erb
...
<tbody>
<% @boms.each do |line| %>
<% if line == @bom %>
<%= render("form_in_table", form_objects: @bom , button_text: "Update") %>
<% else %>
<%= render("bom_in_table", line: line) %>
<% end %>
<% end %>
<% if @bom.new_record? %>
<%= render("form_in_table", form_objects: [@li, @bom] , button_text: "Add") %>
<% end %>
</tbody>
...
_form_in_table.html.erb
<%= form_for(form_objects, html: {class: "form-in-table"}) do |f| %>
<tr>
<td><%= f.text_field :quantity %></td>
<td colspan="2">
<%= f.select(:part_id,
options_from_collection_for_select(@parts, :id, :pricebook_name),
prompt: "Select a Part",) %></td>
<td></td>
<td></td>
<td></td>
<td><%= f.submit(button_text, class: "btn btn-primary btn-mini") %></td>
</tr>
<% end %>
_bom_in_table.html.erb
<tr>
<td><%= line.quantity%></td>
<td><%= line.part_number %></td>
<td><%= line.part_description %></td>
<td><%= number_to_currency(line.part_cost) %></td>
<td><%= line.part_unit %></td>
<td><%= number_to_currency(line.extension) %></td>
<td><%= link_to('Edit', edit_bom_path(line)) %></td>
</tr>
boms_controller.rb
...
def edit
@bom = Bom.find(params[:id])
@li = @bom.line_item
@boms = @li.boms.sorted_by_part_number
@parts = Part.sorted_by_number
render 'index'
end
...
경우 이것은 코드를 해독에 유용하다 / 의도, 나는 line_items, 부품 및 BOM을의 컬렉션을 가지고, LINE_ITEM 많은 BOM을 가지고 있으며, LINE_ITEM는 BOM을 통해 많은 부분이 있습니다. 부품 / 광고 항목 관계에 더하여, BOM의 양이있다. BOM을 재료의 법안에 대한 짧습니다. @li가 조작되고있는 LINE_ITEM입니다. 난에 문제를 갖는 형태 속하는 광고 항목에 추가 / 된 BOM (quantitys 부품)이 수집 편집 / 볼 수있다.
로그를 추가
Started GET "/line_items/8/boms" for 127.0.0.1 at 2013-10-14 14:27:27 -0400
Processing by BomsController#index as HTML
Parameters: {"line_item_id"=>"8"}
[1m[35mLineItem Load (0.0ms)[0m SELECT "line_items".* FROM "line_items" WHERE "line_items"."id" = ? LIMIT 1 [["id", "8"]]
[1m[36mLineItemSubClass Load (1.0ms)[0m [1mSELECT "line_item_sub_classes".* FROM "line_item_sub_classes" WHERE "line_item_sub_classes"."id" = ? ORDER BY "line_item_sub_classes"."id" ASC LIMIT 1[0m [["id", 8]]
[1m[35mLineItemClass Load (4.0ms)[0m SELECT "line_item_classes".* FROM "line_item_classes" WHERE "line_item_classes"."id" = ? ORDER BY "line_item_classes"."id" ASC LIMIT 1 [["id", 1]]
Rendered shared/_error_messages.html.erb (3.0ms)
[1m[36mBom Load (1.0ms)[0m [1mSELECT "boms".* FROM "boms" INNER JOIN "parts" ON "parts"."id" = "boms"."part_id" WHERE "boms"."line_item_id" = ? ORDER BY "parts".number ASC[0m [["line_item_id", 8]]
[1m[35mPart Load (0.0ms)[0m SELECT "parts".* FROM "parts" WHERE "parts"."id" = ? ORDER BY "parts"."id" ASC LIMIT 1 [["id", 1]]
Rendered boms/_bom_in_table.html.erb (96.0ms)
[1m[36mPart Load (1.0ms)[0m [1mSELECT "parts".* FROM "parts" ORDER BY "parts".number ASC[0m
Rendered boms/_form_in_table.html.erb (103.0ms)
[1m[35m (24.0ms)[0m SELECT SUM(quantity * cost) AS sum_id FROM "parts" INNER JOIN "boms" ON "boms"."part_id" = "parts"."id" WHERE "boms"."line_item_id" = 8
Rendered boms/index.html.erb within layouts/boms (477.0ms)
Rendered layouts/_shim.html.erb (1.0ms)
Rendered layouts/_header.html.erb (0.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Rendered layouts/application.html.erb (69.0ms)
Completed 200 OK in 671ms (Views: 601.0ms | ActiveRecord: 31.0ms)
Started GET "/boms/22/edit" for 127.0.0.1 at 2013-10-14 14:28:13 -0400
Processing by BomsController#edit as HTML
Parameters: {"id"=>"22"}
[1m[36mBom Load (0.0ms)[0m [1mSELECT "boms".* FROM "boms" WHERE "boms"."id" = ? LIMIT 1[0m [["id", "22"]]
[1m[35mLineItem Load (1.0ms)[0m SELECT "line_items".* FROM "line_items" WHERE "line_items"."id" = ? ORDER BY "line_items"."id" ASC LIMIT 1 [["id", 8]]
[1m[36mLineItemSubClass Load (1.0ms)[0m [1mSELECT "line_item_sub_classes".* FROM "line_item_sub_classes" WHERE "line_item_sub_classes"."id" = ? ORDER BY "line_item_sub_classes"."id" ASC LIMIT 1[0m [["id", 8]]
[1m[35mLineItemClass Load (0.0ms)[0m SELECT "line_item_classes".* FROM "line_item_classes" WHERE "line_item_classes"."id" = ? ORDER BY "line_item_classes"."id" ASC LIMIT 1 [["id", 1]]
Rendered shared/_error_messages.html.erb (0.0ms)
[1m[36mBom Load (1.0ms)[0m [1mSELECT "boms".* FROM "boms" INNER JOIN "parts" ON "parts"."id" = "boms"."part_id" WHERE "boms"."line_item_id" = ? ORDER BY "parts".number ASC[0m [["line_item_id", 8]]
[1m[35mPart Load (0.0ms)[0m SELECT "parts".* FROM "parts" ORDER BY "parts".number ASC
Rendered boms/_form_in_table.html.erb (25.0ms)
[1m[36m (0.0ms)[0m [1mSELECT SUM(quantity * cost) AS sum_id FROM "parts" INNER JOIN "boms" ON "boms"."part_id" = "parts"."id" WHERE "boms"."line_item_id" = 8[0m
Rendered boms/index.html.erb within layouts/boms (41.0ms)
Rendered layouts/_shim.html.erb (0.0ms)
Rendered layouts/_header.html.erb (1.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Rendered layouts/application.html.erb (54.0ms)
Completed 200 OK in 113ms (Views: 104.0ms | ActiveRecord: 3.0ms)
Started GET "/boms/22/edit" for 127.0.0.1 at 2013-10-14 14:28:37 -0400
Processing by BomsController#edit as HTML
Parameters: {"id"=>"22"}
[1m[35mBom Load (0.0ms)[0m SELECT "boms".* FROM "boms" WHERE "boms"."id" = ? LIMIT 1 [["id", "22"]]
[1m[36mLineItem Load (0.0ms)[0m [1mSELECT "line_items".* FROM "line_items" WHERE "line_items"."id" = ? ORDER BY "line_items"."id" ASC LIMIT 1[0m [["id", 8]]
[1m[35mLineItemSubClass Load (0.0ms)[0m SELECT "line_item_sub_classes".* FROM "line_item_sub_classes" WHERE "line_item_sub_classes"."id" = ? ORDER BY "line_item_sub_classes"."id" ASC LIMIT 1 [["id", 8]]
[1m[36mLineItemClass Load (1.0ms)[0m [1mSELECT "line_item_classes".* FROM "line_item_classes" WHERE "line_item_classes"."id" = ? ORDER BY "line_item_classes"."id" ASC LIMIT 1[0m [["id", 1]]
Rendered shared/_error_messages.html.erb (0.0ms)
[1m[35mBom Load (1.0ms)[0m SELECT "boms".* FROM "boms" INNER JOIN "parts" ON "parts"."id" = "boms"."part_id" WHERE "boms"."line_item_id" = ? ORDER BY "parts".number ASC [["line_item_id", 8]]
[1m[36mPart Load (0.0ms)[0m [1mSELECT "parts".* FROM "parts" ORDER BY "parts".number ASC[0m
Rendered boms/_form_in_table.html.erb (5.0ms)
[1m[35m (0.0ms)[0m SELECT SUM(quantity * cost) AS sum_id FROM "parts" INNER JOIN "boms" ON "boms"."part_id" = "parts"."id" WHERE "boms"."line_item_id" = 8
Rendered boms/index.html.erb within layouts/boms (27.0ms)
Rendered layouts/_shim.html.erb (1.0ms)
Rendered layouts/_header.html.erb (8.0ms)
Rendered layouts/_footer.html.erb (0.0ms)
Rendered layouts/application.html.erb (60.0ms)
Completed 200 OK in 131ms (Views: 94.0ms | ActiveRecord: 2.0ms)
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:38 -0400
Started GET "/assets/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/parts.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-10-14 14:28:39 -0400
해결법
-
==============================
1.나는 이것이 HTML의 문제가 아니라 레일 문제입니다 생각합니다. 표 안에 이러한 논의 형당,