0

私はレールに本当に慣れていないので、これが私の最初のプロジェクトです。エラーを調査する方法を理解するのを手伝ってもらえますか?

ランサックとジオコードを使用して検索機能を作成し、データベース内のオブジェクトをその場所に基づいて表示しました。

ここで例外があります:

@cars_address = Car.where(active: true).near(session[:loc_search], 5, order: 'distance')

コンソールに次のエラーが表示されます。

例外 = サポートされていない引数の型: 0 (整数)

検索フォームに長い文字列を入力すると、エラーが発生します。すべて「ミラノ」のようなもので機能しますが、「ミラノ、ミラノ、イタリアのメトロポリタンシティ」などのジオコンプリート提案で例外が発生しました。

これはコントローラーです:

  def search

if params[:q].present? && params[:q].strip != ""
  session[:loc_search] = params[:q]
end
if session[:loc_search] && session[:loc_search] != ""


  #Something Wrong Here?
  @cars_address = Car.where(active: true).near(session[:loc_search], 5, order: 'distance')
  else
  @cars_address = Car.where(active: true).all

end

@q = @cars_address.ransack(params[:q])
@cars = @q.result

@arrCars = @cars.to_a

これは例外のスタックトレースです

 Processing by PagesController#search as HTML
  Parameters: {"q"=>"Milano, Metropolitan City of Milan, Italy", "start_date"=>"", "end_date"=>"", "commit"=>"Search"}

[4, 13] in /mnt/c/Users/haget/Documents/GitHub/Clapp/app/controllers/pages_controller.rb
    4:     @cars = Car.where(active: true).limit(3)
    5:   end
    6:
    7:   def search
    8:     byebug
=>  9:     if params[:q].present? && params[:q].strip != ""
   10:       session[:loc_search] = params[:q]
   11:     end
   12:     if session[:loc_search] && session[:loc_search] != ""
   13:
(byebug)

[95, 104] in /home/haget/.rvm/gems/ruby-2.7.0/gems/puma-4.3.5/lib/puma/thread_pool.rb
    95:         not_full = @not_full
    96:
    97:         extra = @extra.map { |i| i.new }
    98:
    99:         while true
=> 100:           work = nil
   101:
   102:           continue = true
   103:
   104:           mutex.synchronize do
(byebug)

[19, 28] in /home/haget/.rvm/gems/ruby-2.7.0/gems/actionpack-6.0.3.2/lib/action_controller/metal/rescue.rb
   19:
   20:     private
   21:       def process_action(*args)
   22:         super
   23:       rescue Exception => exception
=> 24:         request.env["action_dispatch.show_detailed_exceptions"] ||= show_detailed_exceptions?
   25:         rescue_with_handler(exception) || raise
   26:       end
   27:   end
   28: end
(byebug)

[32, 41] in /home/haget/.rvm/gems/ruby-2.7.0/gems/actionpack-6.0.3.2/lib/action_controller/metal/instrumentation.rb
   32:       ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
   33:         super.tap do
   34:           payload[:status] = response.status
   35:         end
   36:       ensure
=> 37:         append_info_to_payload(payload)
   38:       end
   39:     end
   40:
   41:     def render(*args)
(byebug)

[20, 29] in /home/haget/.rvm/gems/ruby-2.7.0/gems/activesupport-6.0.3.2/lib/active_support/notifications/instrumenter.rb
   20:       def instrument(name, payload = {})
   21:         # some of the listeners might have state
   22:         listeners_state = start name, payload
   23:         begin
   24:           yield payload if block_given?
=> 25:         rescue Exception => e
   26:           payload[:exception] = [e.class.name, e.message]
   27:           payload[:exception_object] = e
   28:           raise e
   29:         ensure
(byebug)
Completed 500 Internal Server Error in 13406ms (ActiveRecord: 0.0ms | Allocations: 788474)



[36, 45] in /home/haget/.rvm/gems/ruby-2.7.0/gems/actionview-6.0.3.2/lib/action_view/rendering.rb
   36:     # Overwrite process to setup I18n proxy.
   37:     def process(*) #:nodoc:
   38:       old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
   39:       super
   40:     ensure
=> 41:       I18n.config = old_config
   42:     end
   43:
   44:     module ClassMethods
   45:       def _routes
(byebug)

[25, 34] in /home/haget/.rvm/gems/ruby-2.7.0/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/callbacks.rb
   25:       error = nil
   26:       result = run_callbacks :call do
   27:         @app.call(env)
   28:       rescue => error
   29:       end
=> 30:       raise error if error
   31:       result
   32:     end
   33:   end
   34: end
(byebug)

[12, 21] in /home/haget/.rvm/gems/ruby-2.7.0/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/executor.rb
   12:       state = @executor.run!
   13:       begin
   14:         response = @app.call(env)
   15:         returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
   16:       ensure
=> 17:         state.complete! unless returned
   18:       end
   19:     end
   20:   end
   21: end
(byebug)

[36, 45] in /home/haget/.rvm/gems/ruby-2.7.0/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/debug_exceptions.rb
   36:         raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
   37:       end
   38:
   39:       response
   40:     rescue Exception => exception
=> 41:       invoke_interceptors(request, exception)
   42:       raise exception unless request.show_exceptions?
   43:       render_exception(request, exception)
   44:     end
   45:
(byebug)

ArgumentError (Unsupported argument type: 0 (Integer)):

app/controllers/pages_controller.rb:16:in `search'

解決した

ジオコーダー自体は、オートロケーションの提案によって提案されたいくつかの長い文字列から座標を返すことができませんでした。

Geocoder に関するこの Medium の記事をフォローしています

4

1 に答える 1