我正在从下拉菜单中选择一个客户,并根据选择在下一个下拉菜单中显示部门。
但是它给出了未定义的局部变量或方法f
NameError at /cus_departments
undefined local variable or method `f' for #<#<Class:0x000001078cbf88>:0x0000010782a138>这是我的视图文件
new.html.haml
.page-content
.page-header
%h1 New agreement
.row
.col-xs-12
= render :partial => 'form'
.actions
= link_to 'Back', agreements_path_form.html.haml
= form_for @agreement, :html => {:class => 'form-horizontal', :role => 'form'} do |f|
.form-group
%label.col-sm-3.control-label.no-padding-right.form-field-2
= f.label :agreement_customer, 'Agreement customer'
.col-sm-9
#form-field-2.col-xs-10.col-sm-5.input.movies
= f.select :agreement_customer, options_from_collection_for_select(Customer.all, :id, :customer_name), prompt: true
.space-4
.form-group
%label.col-sm-3.control-label.no-padding-right.form-field-2
= f.label :agreement_customer_dept, 'Customer department'
.col-sm-9
#form-field-2.col-xs-10.col-sm-5.input.characters
%select{:class => 'form-control'}
%option
.space-4agreement.js.coffee
$ ->
$('.input.movies select').change ->
url = "/cus_departments?customer_id=" + $(this).val() # get the selected value from the drop-down
$('.input.characters select').load(url) # load the response from the url into the specified element(s)agreements_controller.rb
def cus_departments
@customer = Customer.find_by_id(params[:customer_id])
@departments = @customer.departments
render :partial => 'departments'
end_departments.html.haml
= collection_select(:department, :customer_id, @departments, :id, :department, :prompt => "Select a department")有没有人能帮我一下?
发布于 2014-01-31 17:20:09
您提供的内容有点令人困惑,但据我所知,我认为问题在于将检索到的值加载到选择框中。用户远程javascript或rjs这些都是强大的,完美的这种类型的需求。如果你希望,我将发送一些代码样本。:)
https://stackoverflow.com/questions/21473839
复制相似问题