多分私はこのコードをあまりにも長く見てきましたが、私がやっていることは簡単なことですが、私のコードはまだ動作していません。レールは未定義のメソッドですがメソッドが存在します
私はモデムを使用してコントローラにパラメータを送信します。コントローラにパラメータを送信する必要がありますが、代わりにundefined method 'ignore_reason=' for nil:NilClass
が表示されます。
controllers/network_hosts
方法defer_host
に提出するモーダル
<div class="modal fade" id="deferHostModal" tabindex="-1" role="dialog" aria-labelledby="deferHostLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="deferHostLabel">Defer a Host</h4>
</div>
<div class="modal-body">
<p>Defering a host means that you're choosing to ignore the security risks that Neo has identified for the given host.
This host will be ignored from future security score calculations. By filling in the information below, you will defer risk for the host for 30 days.</p>
<br/>
<%= form_for @network_host, url: {controller: "network_hosts", action: "defer_host"} do |f| %>
<%= f.hidden_field :id, class: "form-control", required: "required" %>
<%= f.label :ignore_reason, "Defer Reason" %>
<%= f.text_area :ignore_reason, class: "form-control", required: "required" %>
<br/>
<%= f.label :ignore_name, "Your Name" %>
<%= f.text_field :ignore_name, class: "form-control", required: "required" %>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<%= f.submit "Save changes", class: "btn btn-primary btn-success" %>
</div>
<% end %>
</div>
</div>
</div>
:
def defer_host
@network_host = NetworkHost.where(id: params[:id]).first
@network_host.ignore_reason = params[:ignore_reason]
@network_host.ignore_name = params[:ignore_name]
@network_host.ignore_flag = true
@network_host.ignore_date = 30.days.from_now
@network_host.save
redirect_to root_path
end
は私がignore_reason
、ignore_name
、ignore_date
、ignore_flag
を追加した最新の移行後、私のRailsサーバーを再起動しました。パラメータはRailsの上、渡されていることを確認するために、また
#<NetworkHost id: 76, location_id: 14, mac_address: "D0:63:B4:00:5B:40", ip_address: "10.10.10.106", hostname: "OpenELEC", created_at: "2016-02-19 01:03:24", updated_at: "2016-04-14 19:30:21", deleted_at: nil, os_vendor: "Unknown", nickname: nil, vendor: "Unknown", os: "Unknown", ignore_reason: nil, ignore_name: nil, ignore_date: nil, ignore_flag: nil>
:NetworkHost
の
サンプルRailsのコンソール出力は、フィールドがそこに書き込みをしていることを確認するために、エラーページ(未定義のメソッドエラーを示す)、パラメータは、底部にある:
Parameters:
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"a7kB1fDirzJFtRR2hBVt/64Z02ufxMzTfpZgKJoWSFI=",
"network_host"=>{"id"=>"76",
"ignore_reason"=>"test defer",
"ignore_name"=>"JF"},
"commit"=>"Save changes"}
ご協力いただきまして誠にありがとうございます。
これらのネストされたパラメータを気にしないでください!ありがとう@ilya – Godzilla74
@ Godzilla74あなたはようこそ) – Ilya