2016-05-31 101 views
0

我有一个表单需要提交给控制器中的“更新”操作。 “show”操作被调用,而“update”操作从不运行。Rails显示操作被调用而不是更新操作

我的路线:

 evaluations GET /evaluations(.:format)    evaluations#index 
        POST /evaluations(.:format)    evaluations#create 
    new_evaluation GET /evaluations/new(.:format)   evaluations#new 
    edit_evaluation GET /evaluations/:id/edit(.:format)  evaluations#edit 
     evaluation GET /evaluations/:id(.:format)   evaluations#show 
        PATCH /evaluations/:id(.:format)   evaluations#update 
        PUT /evaluations/:id(.:format)   evaluations#update 
        DELETE /evaluations/:id(.:format)   evaluations#destroy 

的形式创建:

action: "<%= evaluation_path %>", 
 
method: "patch" //I have tried both "post" and "put" as well

我的控制器有一个有效的 “更新” 行动也是如此。

+0

表单是从传递给React组件的Javascript对象呈现的。 – cmwall

+0

请向我们展示整个表单代码,至少form_for或form_tag。 – Leito

+0

没有form_for标签。表单是通过将JavaScript对象传递给React组件来创建的,React组件然后设置动作和方法。 – cmwall

回答

1

你不应该忘记通过idrecord,就像如下:

action: evaluation_path(@evaluation), method: "patch" 

也顺便避免action键:

button_to "Update", evaluation_path(@evaluation), method: "patch" 
+0

谢谢,但这仍然称为'show'方法。 – cmwall

+0

@cmwall upadted答案 –

1

尝试方法PATCH大写字母表示。只是一种预感。 HTTP动词通常区分大小写,并且意味着大写。