0

レールの関係をクリアできるように、空白のオブジェクトを選択して投稿できるようにしたいと思います。デフォルトでは、:include_blankエントリで選択されているときにPOSTすると、何も投稿されないため、古い関係は削除されません。だから私は0idの空白の項目を配列に追加しようとしています。

オリジナル:

<%= select_f f,:config_template_id, @operatingsystem.config_templates.where(:template_kind_id => f.object.template_kind_id), :id, :name, {:include_blank => true}, { :label => f.object.template_kind } %>

私の:

<%= select_f f,:config_template_id, @operatingsystem.config_templates.where(:template_kind_id => f.object.template_kind_id).collect { |c| [c.name, c.id]}.insert(0, ['', 0]) %>

「引数の数が間違っています(5の場合は3)」というエラーが表示されますが、何が欠けているのかわかりません。ポインタはありますか?(また、ウェブ上のどこにもselect_fが見つかりません。グーグルは、_を無視しているので、検索はオープンエンドの方法だと思います。..Rails 3の場合、他のものを使用する必要がありますか?)

4

1 に答える 1

1

元のコードブロックに渡していた3番目、4番目、5番目、および6番目の引数を省略しました。いずれにせよselect_f、少なくとも5つの引数が必要です。オリジナルでは、以下をに渡しますselect_f (わかりやすくするために1行に1つの引数)

f,
:config_template_id, 
@operatingsystem.config_templates.where(:template_kind_id => f.object.template_kind_id), 
:id, 
:name, 
{:include_blank => true}, 
{ :label => f.object.template_kind }

あなたの新しい(壊れた)電話では、あなたはただ通過しているだけです

f, 
:config_template_id, 
@operatingsystem.config_templates.where(:template_kind_id => f.object.template_kind_id).collect { |c| [c.name, c.id]}.insert(0, ['', 0])

最初のメソッド呼び出しを使用し、3番目の引数を置き換えるだけです。

f,
:config_template_id, 
@operatingsystem.config_templates.where(:template_kind_id => f.object.template_kind_id).collect { |c| [c.name, c.id]}.insert(0, ['', 0])
:id, 
:name, 
{:include_blank => true}, 
{ :label => f.object.template_kind }

最後に、:include_blank => trueを渡したくないが、それでもラベルが必要な場合は、nilまたは{}5番目の引数に渡すだけです。

f,
:config_template_id, 
@operatingsystem.config_templates.where(:template_kind_id => f.object.template_kind_id).collect { |c| [c.name, c.id]}.insert(0, ['', 0])
:id, 
:name, 
nil,
{ :label => f.object.template_kind }

そして、全体として1行で:

<%= select_f f, :config_template_id, @operatingsystem.config_templates.where(:template_kind_id => f.object.template_kind_id).collect { |c| [c.name, c.id]}.insert(0, ['', 0]), :id, :name, nil, { :label => f.object.template_kind } %>

select_fAPIがどこにあるのか、または自分で作成したのかわからないため、これが機能することを保証できません。しかし、これはあなたを正しい方向に動かすはずです。

于 2012-10-26T21:23:31.337 に答える