Rails - 从另一个控制器中的一个控制器调用部分

时间:2016-02-02 17:19:37

标签: ruby-on-rails carmen

我正在尝试以db的形式选择一个国家及其地区。我有一个表单出现在会话#视图的新动作中,但位于access_requests/_form.html.slim。它发布到access_requests #create。在表单中,我在views / sessions文件夹中有subregion_select部分。一切正常,除非我发布表单时收到以下错误消息:

Missing partial access_requests/_subregion_select

access_requests / _form.html.slim

= simple_form_for object, url: access_requests_path do |f|
  .form-group
    = f.input :first_name, input_html: { class: "form-control" }
  ...
  = f.simple_fields_for :extra_attributes do |extra_fields|
  .form-group
    = extra_fields.input :country, as: :select, collection: site_countries, prompt: 'Please select a country', label: "Franchisee Billing Country", input_html: { class: "form-control" }
    .form-group
    = label_tag "Franchisee Billing State/Province"
    = render partial: "subregion_select"

_subregion_select.html.slim

#states_provinces_wrapper
  - country_code ||= params[:country_code]
  - country = Carmen::Country.coded(country_code)

  - if country.nil?
    em Please select a country above
  - else
    = select "access_request_form[extra_attributes]", "province", states_provinces_for_select(country_code), class: "form-control"

的application.js

$(document).ready(function(){
  $('#access_request_form_extra_attributes_country').change(function(event) {
    var country_code, select_wrapper, url;
    select_wrapper = $('#states_provinces_wrapper');
    $('select', select_wrapper).attr('disabled', true);
    country_code = $(this).val();
    url = "/subregion_options?country_code=" + country_code;
    select_wrapper.load(url);
  });
});

sessions_controller.rb

def subregion_options
  render partial: "subregion_select"
end

1 个答案:

答案 0 :(得分:1)

使用部分的完整路径(相对于app / views):

GROUP BY Bank.no