开发者

Rails restful non-GET requests from inline links without Javascript

It would appear that Rails does not support inline links for non-GET requests. Out of the box, the Rails scaffolding system uses inline links for deletes.

While rails.js perfectly adequately appends the csrf tokens before sending the delete request, browsers without Javascript bypass this step entirely and just send a GET request to the resource proper instead.

My current application is also designed in a way such that other non-GET requests would be initiated from inline links.

The non-solution I came up with was to create a 'deleting view' counterpart to #destroy as #new is to #create and #edit is to #update and then just to have a form to carry out the logic, delegating csrf planting to the form builder (which it does do out of the box).

The trouble with that solution is that more steps are required than ideal. Obviously, we can say that the inconvenience is not too great, and if you're using a non-JS browser, you can probably put up with a less than modern UX. But I'd like to have a better solution.

So, the thing that popped to mind was to use forms in place of links. The only trouble is that the开发者_如何学编程 only way to submit a form in a non-JS browser is to have a submit button. But the input type="submit" is a replaced element and doesn't style the same as an ordinary element. Trying to get that to line up cross-browser with regular inline or inline-block text was an exercise in frustration.

So what's the best way to do this. And is there any profound reason why Rails' scaffolds appear to be non-functional on non-JS browsers out of the box?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜