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
,但是您定义了路由useget
通过:“获取”将更改为通过:“发布”
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'