link_to 到一个页面,但控制器来自 Rails 中的另一个页面

发布于 2024-11-18 12:11:09 字数 635 浏览 3 评论 0原文

我在堆栈上看到了一些类似的问题,但我不认为这是重复的,因为我得到的每个答案都特定于一个潜在问题。

我会保持简单。我想知道如何单击链接,让它将用户带到一个页面,但从另一个页面执行 def。这是一个网络爬虫的 Rails 应用程序,我认为它很简单,但对我来说却很糟糕。

目前我有:

<td><%= link_to 'Crawl!', crawl_path  :controller => :crawl, :action => :crawl  %>

这会在爬虫运行完成后将用户带到爬虫的索引页面。 我想做的是将它们重定向到不同的页面。即 jobs_path,它显示爬虫站点和状态的列表(这工作正常,我只是想将其包含在内以实现相关性)。如果我这样尝试:

<td><%= link_to 'Crawl!', jobs_path,  :controller => :crawl, :action => :crawl  %>

用户被定向到作业页面,但爬虫脚本从未运行,因此作业列表从未更新。根据记录,每个作业只是一个 url 和它所在的深度。

这只是一个语法错误还是我离谱了?

任何帮助表示赞赏。

I've seen some similar questions on stack but I don't think this is a duplicate as each answer I've gottent has been specific to one underlying problem.

Ill keep it simple. I'd like to know how to click a link, have it take the user to one page but execute a def from another. This is in a rails application of a web crawler and Its something I thought would be quite simple but turned nasty on me.

At the moment I have:

<td><%= link_to 'Crawl!', crawl_path  :controller => :crawl, :action => :crawl  %>

This takes the user to the crawler's index page after its done running.
What I would like to do is redirect them to a different page. Namely jobs_path which shows a list of the crawlers sites and status (this is working fine, I just want to included it for relevance). If I try it like this:

<td><%= link_to 'Crawl!', jobs_path,  :controller => :crawl, :action => :crawl  %>

The user is directed to the jobs page but the crawler script never ran and thus the jobs list was never update. For the record, each job is just a url and the depth that it lies at.

Is this just a syntactical error or am I miles off the mark?

Any help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疑心病 2024-11-25 12:11:10

您将 crawl#crawl 中的 redirect_to 设置为了什么?也许将其设置为在完成后重定向到 jobs_path

What have you set your redirect_to in crawl#crawl as? Perhaps set it to redirect to jobs_path upon completion?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文