2013-07-08 86 views
1

所有。我遵循carmen-rails文檔,雖然我使用的是rails4,但在選擇國家時,我無法讓州分區域工作。事實上,當離開子區域代碼時,我甚至無法導航到該網站。我得到這個錯誤:rails國家選擇與國家分區在rails4

localhost:3000 

Processing by OrdersController#new as HTML 
    Rendered orders/_subregion_select.html.erb (1.9ms) 
    Rendered orders/_form.html.erb (773.3ms) 
    Rendered orders/new.html.erb within layouts/application (775.8ms) 
Completed 500 Internal Server Error in 784ms 

ActionView::Template::Error (undefined method `downcase' for nil:NilClass): 
    1: <div id="order_state_wrapper"> 
    2: <% parent_region ||= params[:parent_region] %> 
    3: <% country = Carmen::Country.coded(parent_region) %> 
    4: 
    5: <% if country.nil? %> 
    6:  <em>Please select a country above</em> 
    app/views/orders/_subregion_select.html.erb:3:in `_app_views_orders__subregion_select_html_erb__937058573181156642_69893053026600' 
    app/views/orders/_form.html.erb:100:in `block in _app_views_orders__form_html_erb__3775537416523760398_69893046471120' 
    app/views/orders/_form.html.erb:1:in `_app_views_orders__form_html_erb__3775537416523760398_69893046471120' 
    app/views/orders/new.html.erb:6:in `_app_views_orders_new_html_erb__3931135682021831649_69893046299220' 

看起來不像的(國家,「美國」,在這種情況下)paramater正在從,因爲它是「無」親區域通過。任何洞察力得到這個工作(我假設與rails4)?

應用程序/視圖/命令/ _form.html.erb

<div class="control-group"> 
    <div class="field"> 
    <%= f.label :country, 'Country' %> 
    <%= f.country_select :country, priority: %w(US CA), prompt: 'Please select a country' %> 
    </div> 
    <div class="field"> 
    <%= f.label :state %><br /> 
    <%= render partial: 'subregion_select', locals: {parent_region: f.object.country} %> 
    </div> 
</div> 

應用程序/視圖/命令/ _subregion_select.html.erb

<div id="order_state_wrapper"> 
    <% parent_region ||= params[: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, parent_region) %> 
    <% else %> 
    <%= text_field(:order, :state) %> 
    <% end %> 
</div> 

應用程序/資產/ Java腳本/ orders.js。咖啡

# Place all the behaviors and hooks related to the matching controller here. 
# All this logic will automatically be available in application.js. 
# You can use CoffeeScript in this file: http://coffeescript.org/ 

$ -> 
    $('select#order_country').change (event) -> 
    select_wrapper = $('#order_state_wrapper') 

    $('select', select_wrapper).attr('disabled', true) 

    country = $(this).val() 

    url = "/orders/subregion_options?parent_region=#{country}" 
    select_wrapper.load(url) 

的config/routes.rb中

get '/orders/subregion_options' => 'orders#subregion_options' 

#耙路線

   Prefix  Verb URI Pattern       Controller#Action 
orders_subregion_options GET /orders/subregion_options(.:format) orders#subregion_options 

,並瀏覽到該次區域的路線時,直接和指定的國家:

http://localhost:3000/orders/subregion_options?parent_region=%22US%22 

Started GET "/orders/subregion_options?parent_region=%22US%22" for 192.168.122.1 at 2013-07-08 13:20:21 -0400 
Processing by OrdersController#subregion_options as HTML 
    Parameters: {"parent_region"=>"\"US\""} 
DEPRECATION WARNING: Relation#first with finder options is deprecated. Please build a scope and then call #first on it instead. (called from service at /usr/local/rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/webrick/httpserver.rb:138) 
    User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1 
    Rendered orders/_subregion_select.html.erb (0.2ms) 
Completed 200 OK in 4ms (Views: 1.3ms | ActiveRecord: 0.2ms) 
+0

忘了說什麼版本我使用的卡門: [根@軌]#grep的-i卡門的Gemfile 寶石 '卡門護欄',:git的=> 'https://github.com/freerunningtechnologies/carmen-rails',:branch =>'rails4' [root @ rails]#bundle show carmen-rails /usr/local/rvm/gems/ruby-2.0.0 -p195/bundler/gems/carmen-rails-92d6d10c930d – olveram

+0

我在Rails 3.2.15上遇到同樣的錯誤,所以它不是Rails 4的特定問題。 –

回答

1

卡門軌道上沒有http://ready4rails4.net/註冊的寶石,GitHub的頁面上它寫入

carmen-rails is a Rails 3 plugin that supplies two new form helper methods: country_select and subregion_select.

plus on travis-ci.org https://travis-ci.org/jim/carmen-rails所有的版本都使用rails 3.2完成。

我會說寶石不是Rails 4準備好了。

你應該在github頁面上打開一個問題。


看過你的評論後,我檢查了你使用的分支,除了分支名稱,我沒有看到任何Rails 4相關的提交。

查看更改日誌文件(https://github.com/freerunningtechnologies/carmen-rails/blob/master/CHANGELOG.md)讓我覺得rails 4的兼容性還沒有完成,但也許我錯了。

+0

認爲它沒有準備好rails4。但想知道有人在那裏工作。猜猜我會一直捅它。謝謝。 – olveram

+0

我發現有人正在使用一個適用於某些事物的叉子,所以想通了。 https://github.com/jim/carmen-rails/pull/20 – olveram

+0

我在Rails 3.2.15上遇到同樣的錯誤,所以它不是Rails 4的特定問題。 –

0

我在Rails 3.2.15應用程序中遇到了同樣的錯誤。我必須對卡門寶石進行一點小小的改變才能使其發揮作用。按照這些說明,你應該是金色的:

  1. 在您的項目根目錄中的終端,使用bundle open carmen打開卡門寶石庫。
  2. 找到文件lib/carmen/querying.rb
  3. 更換線15下列要求:

    code = code.try(:downcase) # Codes are all ASCII

我已經提交pull請求原作者所以這可能會在主分支儘快解決,但在那之前你能做到以上或者你可以在你的Gemfile使用my fork如下:

gem 'carmen', github: 'joshuapinter/carmen' 
0

提花小號造成你的錯誤的東西我也跑了出去。

<div id="order_state_code_wrapper"> 
    <% parent_region ||= params[:parent_region] %> 
    <% unless parent_region.nil? %> 
    <% country = Carmen::Country.coded(parent_region) %> 
    <% end%> 
    <% 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> 

您需要添加此清除錯誤

<% unless parent_region.nil? %> 
    <% country = Carmen::Country.coded(parent_region) %> 
    <% end%> 

,除非是在頁面加載第一次parent_region必要是零那個時候

,並刪除/訂單網址路由,因爲它不調用控制器操作subregion_options並使用subregion_options作爲ID

修改後的URL和路線

url = "/subregion_options?parent_region=#{country}" 

get '/subregion_options' => 'orders#subregion_options' 
+0

卡門軌道已準備好導軌4 – Abhishek