carmen rails undefined method `country_code' for nil:NilClass -
i'm having following error while trying pass locals partial:
undefined method `country_code' nil:nilclass
this code looks like:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>trial</title> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <script type="text/javascript"> $(document).ready(function() { $('select#order_country_code').change(function(){select_wrapper = $('#order_state_code_wrapper'); $('select', select_wrapper).attr('disabled', true); country_code = $(this).val(); url = "subregion_options?parent_region=#{country_code}"; $('#order_state_code_wrapper').load(url); }); }); </script> </head> <body> <%= form_for(:order) |f| %> <div class="field"> <%= f.label :country_code %><br /> <%= f.country_select :country_code, priority: %w(us ca), prompt: 'please select country' %> <%= f.label :state_code %><br /> <%= render partial: 'subregion_select', locals: {parent_region: f.object.country_code} %> </div> <% end %> </body> </html>
partial:
<div id="order_state_code_wrapper"> <% parent_region ||= params[:parent_region] %> <% country = carmen::country.coded(parent_region) %> <% if country.nil? %> <em>please select country above</em> <% elsif country.subregions? %> <%= subregion_select(:order, :state_code, parent_region) %> <% else %> <%= text_field(:order, :state_code) %> <% end %> </div>
controller:
class orderscontroller < applicationcontroller layout false def index end def subregion_options render partial: 'subregion_select' end end
routes:
rails.application.routes.draw # priority based upon order of creation: first created -> highest priority. # see how routes lay out "rake routes". # can have root of site routed "root" root 'access#index' match ':controller(/:action(/:id))', :via => [:get, :post] 'subregion_options' => 'orders#subregion_options' end
thank :)
i think need add in appropriate action in controller :
@order = order.new
and in view, instead
form_for(:order)
put
form_for(@order)
add config/routes.rb following:
resources :orders, only: [:index]
Comments
Post a Comment