I can't get Carmen-Rails to work

149 Views Asked by At

I've been unable to get Carmen-Rails to work at all, and I'm really not sure what's going on. (That particular GitHub project is very poorly documented.) Simply put, I'm using the code specified in the demo application but am seeing nothing on my page--just the text that reads "Please select a country above." There are no errors that I can see. Here's the code I'm working with. Any help would be greatly appreciated. (Incidentally, is there a superior alternative to Carmen-Rails or at least one that is actively maintained?)

user.rb

  <div id="order_state_code_wrapper">
    <% parent_region ||= params[:parent_region] %>
    <% logger.info("Parent region is #{parent_region}.") %>
    <% country = Carmen::Country.coded(parent_region) %>

    <% if country.nil? %>
      <em>Please select a country above</em>
    <% elsif country.subregions? %>
      <%= subregion_select(:order, :state_code, parent_region) %>
    <% else %>
      <%= text_field(:order, :state_code) %>
    <% end %>
  </div>

Here's the code inside my controller:

users_controller.rb

  def subregion_options
    render partial: "subregion_select"
  end

Here's the code in my user model:

user.rb

  attr_accessor :avatar, :country_code, :state_code

Here's the JavaScript:

_subregions_select.html.erb

$(function () {
  console.log("klsjdfjf");
  $("#user_country_code").on("change", function () {
    var $selectWrapper = $("#user_state_code_wrapper"),
        countryCode = $(this).val(),
        url;
    $("select", $selectWrapper).attr("disabled", true);
    url = "/users/subregion_options?parent_region=#{country_code}";
    $selectWrapper.load(url);

  });
});

Here's the route I've added to my routes file:

routes.rb

  get "/users/subregion_options" => "users#subregion_options"

Here's my subregion_options partial:

<div id="order_state_code_wrapper">
  <% parent_region ||= params[:parent_region] %>
  <% logger.info("Parent region is #{parent_region}.") %>
  <% country = Carmen::Country.coded(parent_region) %>

  <% if country.nil? %>
    <em>Please select a country above</em>
  <% elsif country.subregions? %>
    <%= subregion_select(:order, :state_code, parent_region) %>
  <% else %>
    <%= text_field(:order, :state_code) %>
  <% end %>
</div>
0

There are 0 best solutions below