0
我的印象是,它可能在Rails link_to
標籤內通過額外的參數下傳遞其他參數。我已經是一個按鈕,用戶可以點擊移動到另一個控制器show
方法/視圖,我需要能夠通過@network_host.id
到新控制器issues_controller.rb
,但它不工作。相反,我被重定向回到我的root_url
。的Rails的link_to中
在用戶將如何做到這一點的順序:
- 用戶導航到www.myserver.com/network_hosts/XX(顯示方法)
- 控制器/在
network_hosts_controller.rb踢
class NetworkHostsController < ApplicationController
before_action :set_network_host, only: [:show]
def show
@network_host = NetworkHost.find(params[:id])
if @network_host
@major_issues = get_host_issues(@network_host, @network_host.last_test, "major")
@minor_issues = get_host_issues(@network_host, @network_host.last_test, "minor")
end
end
end
個
- 視圖/ network_hosts/show.html.erb(用戶點擊的link_to按鈕)
<tbody>
<% @major_issues.to_enum.with_index(1).each do |result, index| %>
<% issue = result.issue %>
<tr>
<td>
<%= link_to '<i class="fa fa-eye"></i>'.html_safe, issue_path({ id: issue.id, host: @network_host.id }), "data-toggle" => "tooltip", "title" => "View" %>
</td>
</tr>
<% end %>
</tbody>
- 應該然後火控制器/ issues_controller.rb(顯示方法,即www.myserver.com/issues/5432),
class IssuesController < ApplicationController
def show
@issue = Issue.find(params[:id])
@network_host = NetworkHost.find(params[:host])
end
end
然而,步驟4不是worki ng,而是返回主頁。所以在我的控制檯,我看着正在傳遞什麼參數,我沒有看到host
參數:
Started GET "/issues/54387" for 127.0.0.1 at 2016-07-13 14:06:49 -0400
Processing by IssuesController#show as HTML
Parameters: {"id"=>"54387"}
上午我實現這個錯了嗎?
什麼是在'意見/ network_hosts/show.html.erb'您呈現的HTML? –
只有一堆'@ network_host'值。沒有任何問題,只是這個該死的鏈接。 – Godzilla74
更具體地說,html中呈現的鏈接是什麼樣的?他們是否正確地獲得了額外的參數? –