问题标签 [named-routing]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby-on-rails-3 - 显式获取路线引发错误
我定义了一个自定义路线:
match 'folio/:id' => 'posts#show', :as => :folio, :via => :get
当我运行rake routes
命令时,我有:
我把这个元素的链接放在我的另一个页面中:link_to post.title, folio_path
,但是当我进入它时,我会抛出一个路由错误:
No route matches {:controller=>"post", :action=>"show"}
为什么会失败?当我post#show
以正常方式使用它时,它就像一个魅力,但我的自定义路线失败了 - 请帮助!
ruby-on-rails - Rails,带有正则表达式的命名路由不起作用
我有以下问题,我不明白为什么它不起作用:
我有路线:
它工作正常
耙路线 | grep 登陆
但是当我尝试建立链接时
我有错误信息
任何想法我做错了什么?
ruby-on-rails - How to map a resource to more than one helper in rails?
I have a Profile model, which is inherited by a Customer and Vendor model. Profile has_many :posts.
When I do
Instead of callind profile_posts_path, form_for will actually call customer_posts_path or vendor_posts_path.
Since I want to have URLs like '/foo', '/bar', where foo and bar are usernames I wrote the routes like this:
This way all requestes to '/foo' will be handled by the ProfilesController (it's the first in the list) and path helpers will be generated so that form_for will work.
However even if it works, this is far from ideal. There is evident repetition. If I need to add another nested resource I would have to add it trice.
So I refactored it like this (I know that this is horrible, but it works):
But this is still horrible. What I would really love to have is the as parameter to be an array, so that I could do:
Is it possible to achieve something similar? Everything would be mapped to the same controller. And no repetition is in act. Any way to create named routes without having to call resources or match or anything...
Thanks in advance
edit: The relation between posts and profiles might become polymorphic in the near future. So the last solution proposed by AJcodex will break.
I find this frustrating, I will probably request this feature for the next rails
ruby-on-rails - 命名空间、form_for 和命名路由
我有两个控制器分组在admin
命名空间下,如下所示:
在 a form_for
for aresource
中,它可以正常工作,如文档中所述:
但是当涉及到像上面这样的命名路由时admin/profile
,我不知道在form_for
. 如果我只是使用form_for(@user)
,则该edit
操作可以正常工作并且表单可以正确显示,但是在提交时出现以下错误:
当我尝试form_for [:admin, @user]
时,表单不显示抱怨:
应该如何form_for be constructed in a named route under a namespace?
ruby-on-rails - Rails 命名路由,从模型生成动态段 URL
仅限 Ruby on Rails 4.2+,拜托!
我一直在寻找有关如何在 Rails 中使 URL 更漂亮的提示,但我正在努力寻找我喜欢的解决方案。
我想要的是:
假设示例:给定主题、课程等具有一堆字段(包括 URL 友好的 slug)的模型,我希望能够
我不想要的:
- 胡闹
to_param
。这是一个肮脏的黑客,完全打破了关注点分离。 - 资源/RESTful 路由。除了“读取”之外,这里没有 CRUD 操作。
link_to 'text', course_path(id: course.id, slug: course.slug)
. 这完全违背了不需要视图知道为课程生成 URL 所需的参数的目的。- 编辑:我知道 FriendlyId 存在,但我只是想了解这种事情是如何完成的以及机制是什么,所以这不是现在的解决方案。
必须有一种方法来告诉命名的路由助手从主题模型对象topic_path(topic)
中获取路由中所需的参数(例如,:slug
,:id
,等等)。
有人知道吗?谢谢!
php - 流明中的反向路由。用它的名字调用路由器
我有一些定义如下的路线:
可以在我的第三条路线(如下)中通过它们的名称来调用这两条路线吗?类似反向路由的东西?
我想要一种Request::response_from($routeNameOrUri)
可以从路由中获取数据的方法(通过调用控制器的操作)
routing - 调用 Slim 命名路由会引发异常
我对 Slim 框架有点陌生,现在我在命名路由方面遇到了这个问题......我的第一条路线的代码是这样的
但是,当我从另一条这样的路线中调用这条路线时
它抛出一个异常“命名路由已经存在,名称为:/admin/login”
我只是不明白...甚至可以从另一条路线调用一条路线吗?正如我在 Slim 文档中看到的那样,它应该是......我哪里出错了?谢谢
php - NotFoundHttpException 命名路由 PHP Laravel 5.2
但是,如果我使用地址/用户/配置文件,我在调用地址/配置文件时总是会出错,它工作得很好。
我的浏览器中显示的错误列表:
我想念哪里?提前致谢。
laravel - LARAVEL: POST and GET routes with same name scrambling link_to_route
I got these routes:
When I call link_to_route()
like so:
It creates this link:
But when I remove the post route, it renders correctly this:
I don't want to change the name of the routes because my system depends on them being the same. How can I solve this?
angular - Angular 2 Named Outlet: Uncaught (in promise): Error: Cannot match any routes. URL Segment:
In a customer management app, I'm trying to have the following:
- Client List (Left Side of the Page)
- Client Details (Right Side of thePage) dashboard/client/id/
- Add a Client (Right Side of the Page). dashboard/client/new.
- Edit a Client (Right Side of the Page). dashboard/client/id/edit
I would like to change the view only on the right side depending what user clicks.
Router Configuration
Client List Component HTML
Client Detail Component
Client Detail Component HTML