Rails控制器需要接受跨域post
我是 Rails 的新手,实际上也是 Web 开发的新手。我正在尝试发表跨域帖子(我认为),但不知道如何去做。
我有一个在 webrick 上运行的 Rails 应用程序,我们称之为“myapp”。
我编写了一个小书签,选择该小书签时,应从用户所在的任何网站获取 URL,并将其发布到“myapp”以供该用户保存(需要提供其电子邮件地址)。我该如何编写一个控制器来处理这个问题?
I'm new to Rails and indeed to web development. I'm trying to do a cross-domain post (I think) and have no clue how to do it.
I have a rails app running on webrick, let's call this 'myapp'.
I have written a bookmarklet which when selected should grab the URL from whatever website the user is on and post it to 'myapp' to be saved for that user (who will need to give his email address). How would I write a controller to deal with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难具体说明您提供的信息量,但一般来说,您需要设置一条路由来处理请求,并定义一个控制器操作来执行您想要的操作。
假设请求看起来像
POST http://myapp.com/bookmarks/create
,其中包含用户电子邮件和他们所在的 url 的参数,这意味着执行如下操作:在 paths.rb 中:
在 bookmarks_controller.rb 中:
It's hard to be specific with the amount of info you've provided, but general, you'll need to set up a route to handle the request, and define a controller action to do what you want with it.
Assuming the requests look something like
POST http://myapp.com/bookmarks/create
with parameters for the user's email and the url they're on, that means doing something like this:in routes.rb:
in bookmarks_controller.rb: