Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ruby on rails中没有与[POST]匹配的路由_Ruby On Rails - Fatal编程技术网

Ruby on rails ruby on rails中没有与[POST]匹配的路由

Ruby on rails ruby on rails中没有与[POST]匹配的路由,ruby-on-rails,Ruby On Rails,在我的pending request页面中,我收到了来自其他用户的一些请求,这些请求附带了两个按钮accept和cancel,当我单击accept按钮时,请求被接受,下面是create方法中accept request的代码 def create @user = Userrequest.select(:RequestFrom).where('RequestTo = ? AND IsApproved = ?', current_user.id, "0") requestfrom

在我的
pending request
页面中,我收到了来自其他用户的一些请求,这些请求附带了两个按钮
accept
cancel
,当我单击accept按钮时,请求被接受,下面是create方法中accept request的代码

  def create
    @user = Userrequest.select(:RequestFrom).where('RequestTo = ? AND IsApproved = ?', current_user.id, "0")
    requestfrom = @user.RequestFrom
    Userrequest.update_attributes('RequestFrom = ? AND RequestTo = ? AND IsApproved = ?', requestfrom,current_user.id,"1")
    @user_request = Userrequest.new( :RequestFrom => requestfrom , :RequestTo => current_user.id , :IsApproved => "1" , :SkillType => "" )
    @user_request.save
    redirect_to '/default'
  end
在create方法中,我正在执行accept-request工作,在accept-request之后,它应该重定向到
default
页面。但是,当我单击“接受”按钮时,会出现以下错误:

No route matches [POST] "/pendingrequest"
以下是路线:

match '/pendingrequests', to: 'static_pages#create', via: 'get'
下面是我的“接受请求”按钮:

<table width="50%">
   <tr>
      <td align="center">
        <div class="button">
          <%= button_to "Accept", '/pendingrequests', { method: :get, :class => "buttonblck" } %>
        </div> 
       </td>
   </tr>
</table>

“按钮链接”}%>
Kindle建议我哪里出错,等待您的回复

谢谢

没有与[POST]“/pendingrequest”匹配的路由

http方法是
POST
,但是您定义了路由use
get

通过:“获取”将
更改为
通过:“发布”

match '/pendingrequests', to: 'static_pages#create', via: 'post'

你可以这样改变

按钮

<%= button_to "Accept", "/pendingrequests", method: :post %>

您可以在终端中键入命令:

rake routes
这通常有助于理解为什么没有路线匹配

试试这场比赛

match '/static_pages', to: 'static_pages#create', via: :get, as: '/pendingrequests'


对于rails 4,您可以直接将
post'/pendingrequests'写入:“静态页面#创建”
match '/static_pages', to: 'static_pages#create', via: :get, as: '/pendingrequests'
match '/static_pages', to: 'static_pages#create', via: :post, as: '/pendingrequests'
match '/static_pages', to: 'static_pages#create', via: :all, as: '/pendingrequests'