Lel*_*don 1 forms ruby-on-rails
我正在为一个我认为非常简单的错误而苦苦挣扎,但我没有 Rails 的复杂性来检测该错误的位置。
我有以下表格:
<%= form_with(url: '/bills/viewer', method: :get) do |f| %>
<%= f.label :congress, 'Congress (i.e. 112)' %>
<%= f.number_field :congress, class: 'form-control' %>
<%= f.label :bill_type, 'Bill type' %>
<%= f.radio_button :bill_type, 'hr' %><%= ' House of Representatives' %>
<%= f.radio_button :bill_type, 's' %><%= ' Senate' %>
<%= f.radio_button :bill_type, 'hjres' %> <%= 'House Joint Resolution' %>
<%= f.radio_button :bill_type, 'sjres' %><%= ' Senate Joint Resolution' %>
<%= f.radio_button :bill_type, 'hconres' %><%= ' House Concurrent Resolution' %>
<%= f.radio_button :bill_type, 'sconres' %><%= ' Senate Concurrent Resolution' %>
<%= f.radio_button :bill_type, 'hres' %><%= ' House Resolution' %>
<%= f.radio_button :bill_type, 'sres' %><%= ' Senate Resolution' %>
<%= f.label :bill_number, 'Bill number' %>
<%= f.number_field :bill_number, class: 'form-control' %>
<%= f.submit "Submit", class: 'form-control' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在我的 config/routes.rb 文件中,我有以下几行:
get '/bills/viewer', to: 'bills#show'
Run Code Online (Sandbox Code Playgroud)
这个想法是我希望表单将提交的信息传输到我的 bills_controller.rb 文件中的“显示”操作,我在下面给出...
def show
@bill = Bill.where("congress = ? AND bill_type = ? AND bill_number = ?", bill_params[:congress], bill_params[:bill_type], bill_params[:bill_number]).take
if @bill.nil?
create
end
@bill_xml = RestClient.get(bill_params[:bill_link])
render :xml => @bill_xml
puts "Called to show!"
Run Code Online (Sandbox Code Playgroud)
...然后将用户重定向到相应的 show.html.erb 文件,我在下面给出...
<% provide(:title, "#{ @bill[:congress] } #{ @bill[:bill_type].upcase } #{ @bill[:bill_number] } | ") %>
<h1><%= "#{ @bill[:congress] } #{ @bill[:bill_type].upcase } #{ @bill[:bill_number] }" %></h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= puts @bill_xml %>
<%= render @bill_xml %>
</div>
</div>
<% puts "RENDERED..." %>
Run Code Online (Sandbox Code Playgroud)
两个“puts”行在那里是为了我自己的调试目的。show 方法中的一个按预期运行,我的控制台显示“调用以显示!”。另一个放置行“RENDERED...”没有显示。此外,该过程完成到200 OK。
单击下面的“提交”后,我将包含控制台的输出...
Started GET "/bills/viewer?utf8=%E2%9C%93&congress=112&bill_type=hr&bill_number=1027&commit=Submit" for 127.0.0.1 at 2018-07-05 15:05:51 -0700
Processing by BillsController#show as JS
Parameters: {"utf8"=>"?", "congress"=>"112", "bill_type"=>"hr", "bill_number"=>"1027", "commit"=>"Submit"}
Unpermitted parameters: :utf8, :commit
Unpermitted parameters: :utf8, :commit
Unpermitted parameters: :utf8, :commit
Bill Load (0.1ms) SELECT "bills".* FROM "bills" WHERE (congress = '112' AND bill_type = 'hr' AND bill_number = '1027') LIMIT ? [["LIMIT", 1]]
Unpermitted parameters: :utf8, :commit
Called to show!
Completed 200 OK in 2980ms (Views: 0.6ms | ActiveRecord: 0.7ms)
Run Code Online (Sandbox Code Playgroud)
但是如果表单要重定向到 show.html.erb 控制台输出应该返回 3XX,不是吗?
我的(显然是错误的)理解是,当我在 bills_controller 中调用 show 操作时,网站应该自动重定向到 views/bills/show.html.erb 页面。为什么不是这种情况,我如何正确地编辑我的代码以便发生所需的重定向?
非常感谢帮助。
The error was resolved by setting local: true within the form_with tag. Nevertheless, I am unclear as to why
| 归档时间: |
|
| 查看次数: |
998 次 |
| 最近记录: |