如何在params值中访问表单中的隐藏字段,但它表示行末尾

问题描述 投票:0回答:1

我有一个想允许我的提案控制者使用的隐藏字段。

[当我提交表格时说

unexpected line end for proposal_params

我在这里想念东西吗?

_ form.html.haml:

%fieldset.col-md-12 = form.label t('.select_tags'), { class: 'tags-label' }
  = form.hidden_field :tags, { class: 'hidden_tags' }

控制器:

def proposal_params 
  params.require(:proposal).permit(:title, :description, :target_audience,
                                   :details, :pitch, :difficulty, :track_id, 
                                   :main_tag_id, comments_attributes: %i[body proposal_id person_id], 
                                   speakers_attributes: %i[person_id id], :tags) 
end

尽管我可以通过执行params[:proposal][:tags]来访问该值。

ruby-on-rails controller haml hidden-field
1个回答
0
投票

在Ruby中,调用带有位置和关键字参数的方法时,必须将关键字参数放在最后:

def foo(*args, **kwargs); end
foo(1, 2, 3, bar: 'baz')
foo(bar: 'baz', 1, 2, 3) # syntax error
params.require(:proposal).permit(:title, :description, :target_audience,
                                   :details, :pitch, :difficulty, :track_id, 
                                   :main_tag_id, :tags,
                                   comments_attributes: %i[body proposal_id person_id], 
                                   speakers_attributes: %i[person_id id])
© www.soinside.com 2019 - 2024. All rights reserved.