ruby on rails - Getting "No route matches" error even though I defined a route -
i’m using rails 4.2.3. i’m trying write ajax method invoke method in controller, i’m getting no-router error. in coffee script, have this
updateall = (arg) -> object = $('#user_object_object').val() day = $('#user_object_day').val() $.ajax url: "/find_by_user_object_and_day" type: 'get' data: {day: day, object: object} success: (data) -> $('total').val(data) error: -> alert "something went wrong"
and in config/routes.rb have this
rails.application.routes.draw resources :user_objects :find_by_user_object_and_day, on: :collection end
and in “./app/controllers/user_objects_controller.rb” have this
def find_by_user_object_and_day userobject.find_by_user_object_and_day(:params[user], :params[object], :params[day]) end
but when ajax method invoked, error produced on server …
f, [2016-02-05t15:52:29.916816 #12058] fatal -- : actioncontroller::routingerror (no route matches [get] "/find_by_user_object_and_day"): actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' web-console (2.2.1) lib/web_console/middleware.rb:39:in `call' actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' railties (4.2.5) lib/rails/rack/logger.rb:38:in `call_app' railties (4.2.5) lib/rails/rack/logger.rb:22:in `call' actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:in `call' rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' rack (1.6.4) lib/rack/runtime.rb:18:in `call' activesupport (4.2.5) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' rack (1.6.4) lib/rack/lock.rb:17:in `call' actionpack (4.2.5) lib/action_dispatch/middleware/static.rb:116:in `call' rack (1.6.4) lib/rack/sendfile.rb:113:in `call' railties (4.2.5) lib/rails/engine.rb:518:in `call' railties (4.2.5) lib/rails/application.rb:165:in `call' rack (1.6.4) lib/rack/lock.rb:17:in `call' rack (1.6.4) lib/rack/content_length.rb:15:in `call' rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service' /users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service' /users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run' /users/davea/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'
as defining route within resources 'user_objects, route available @ /user_objects/find_by_user_object_and_day, not @ /find_by_user_object_and_day.
if want able @ root level /find_by_user_object_and_day need define route @ root level follows:
rails.application.routes.draw '/find_by_user_object_and_day', to: 'user_objects#find_by_user_object_and_day' end
Comments
Post a Comment