Rails 3 路线帮助

发布于 2024-11-07 02:32:06 字数 637 浏览 1 评论 0原文

这可能很简单,但我无法弄清楚。

我正在尝试通过 url“/submit”创建到 :submissions#new 的路由

resources :submissions, :only => [:index, :show, :new, :create]
match 'submit', :to => 'submissions#new'

上面的代码工作正常,但我想阻止标准“资源”创建的 URL “/submissions/new”并且仅使用“/submit”URL。我编写两个 URL 的方式都会呈现submissions#new,这是我不想要的。

当我注释掉“资源”代码行并仅使用“匹配”行时,它无法再找到控制器“submissions_controller”

这是错误消息:

ActionController::RoutingError in Submissions#new

Showing /media/sf_admin/ Projects/lolsnort/app/views/submissions/_form.html.erb 其中第 1 行提出:

没有路由匹配 {:controller=>"submissions"}

任何帮助将不胜感激。谢谢。

this is probably simple, but I can't figure it out.

I'm trying to create a route to :submissions#new via the url "/submit"

resources :submissions, :only => [:index, :show, :new, :create]
match 'submit', :to => 'submissions#new'

The code above works fine, but I want to block the standard "resources" created URL of
"/submissions/new" and only use the "/submit" URL. The way I have it written both URLs will render submissions#new, which I don't want.

When I comment out the "resources" line of code and only use the "match" line, it can no longer find the controller "submissions_controller"

Here is the error message:

ActionController::RoutingError in Submissions#new

Showing /media/sf_admin/Projects/lolsnort/app/views/submissions/_form.html.erb where line #1 raised:

No route matches {:controller=>"submissions"}

Any help would be appreciated. Thanks.

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

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

发布评论

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

评论(1

不弃不离 2024-11-14 02:32:06

尝试一下这个方法:

resources :submissions, :except => [:new]
match 'submit', :to => 'submissions#new', :as => :submit

Try this way out:

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