我在link_to中定义post方法但是我得到了get的路由错误,我已经定义了一个帖子路由

时间:2017-08-01 11:56:25

标签: ruby-on-rails ruby

** 在2017-08-03 12:51:59 +0530开始获取“/ wallpapers / 1 / like?like = true”的127.0.0.1

ActionController :: RoutingError(没有路由匹配[GET]“/ wallpapers / 1 / like”):

actionpack(5.0.4)lib / action_dispatch / middleware / debug_exceptions.rb:53:in call' web-console (3.5.1) lib/web_console/middleware.rb:135:in call_app' web-console(3.5.1)lib / web_console / middleware.rb:28:in block in call' web-console (3.5.1) lib/web_console/middleware.rb:18:in catch' web-console(3.5.1)lib / web_console / middleware.rb:18:in call' actionpack (5.0.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in call' railties(5.0.4)lib / rails / rack / logger.rb:36:in call_app' railties (5.0.4) lib/rails/rack/logger.rb:24:in阻止电话' activesupport(5.0.4)lib / active_support / tagged_logging.rb:69:in block in tagged' activesupport (5.0.4) lib/active_support/tagged_logging.rb:26:in tagged' activesupport(5.0.4)lib / active_support / tagged_logging.rb:69:in tagged' railties (5.0.4) lib/rails/rack/logger.rb:24:in call' sprockets-rails(3.2.0)lib / sprockets / rails / quiet_assets.rb:13:in call' actionpack (5.0.4) lib/action_dispatch/middleware/request_id.rb:24:in call' rack(2.0.3)lib / rack / method_override.rb:22:in call' rack (2.0.3) lib/rack/runtime.rb:22:in call' activesupport(5.0.4)lib / active_support / cache / strategy / local_cache_middleware.rb:28:in call' actionpack (5.0.4) lib/action_dispatch/middleware/executor.rb:12:in call' actionpack(5.0.4)lib / action_dispatch / middleware / static.rb:136:in call' rack (2.0.3) lib/rack/sendfile.rb:111:in call' railties(5.0.4)lib / rails / engine.rb:522:in call' puma (3.9.1) lib/puma/configuration.rb:224:in call' puma(3.9.1)lib / puma / server.rb:602:in handle_request' puma (3.9.1) lib/puma/server.rb:435:in process_client' puma(3.9.1)lib / puma / server.rb:299:in block in run' puma (3.9.1) lib/puma/thread_pool.rb:120:in block in spawn_thread'   在救援/布局中呈现C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb   渲染C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb   呈现C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb(1.5ms)   呈现C集合:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/routes/_route.html.erb [11次​​]( 3.5ms)   呈现C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/routes/_table.html.erb(5.0ms)   渲染C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb   渲染C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb(1.5ms)   在救援/布局中呈现C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.4/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb(1391.8ms) )

**我的routes.rb文件

Rails.application.routes.draw do  
  root 'pages#home'
  get '/home', to: 'pages#home'

  resources :wallpapers do
    member do  
      post 'like'
    end
  end
end

和我的link_to

<%= link_to like_wallpaper_path(@wallpaper), :method => :post  do %>
  <i class="glyphicon glyphicon-thumbs-up"></i>
<% end %> 

1 个答案:

答案 0 :(得分:0)

而不只是method: :postdata: { method: 'post' }。所以你的链接应该是

<%= link_to like_wallpaper_path(@wallpaper), data: { method: 'post' }  do %>
    <i class="glyphicon glyphicon-thumbs-up"></i>
<% end %>