routing

Rails 3 routing - passing params from routes.rb

六眼飞鱼酱① 提交于 2019-11-30 06:15:39
In rails 2.3.5 you could do something like this inside the routes.rb file: map.root :controller => "pages", :action => "show", :id => 3 In rails 3 I haven't found any way to pass a specific parameter (like in rails 2.3.5 with :id => 3). I know I can handle it from the controller and have the same result (which I did), but I was wondering if there is a way to do the same thing in rails 3 from the routes.rb or has it changed because it is better practice for some reason? Are you sure the following doesn't work? root :to => "pages#show", :id => 3 来源: https://stackoverflow.com/questions/3533960

MVC 4.5 Web API Routing not working?

余生颓废 提交于 2019-11-30 05:58:15
问题 The 1st route works. e.g. api/Shelves/SpaceTypes/1 The 2nd route doesn't work. I get multiple actions error. e.g api/Shelves/1 Q) Why? These are my routes: config.Routes.MapHttpRoute( "DefaultApiWithAction", "api/{controller}/{action}/{id}" ); config.Routes.MapHttpRoute( "DefaultApiWithId", "api/{controller}/{id}", null, new { id = @"\d+" } ); This is my controller: public HttpResponseMessage Get(int id) { ... } [ActionName("SpaceTypes")] public HttpResponseMessage GetSpaceTypes(int id) { ...

Express JS reverse URL route (Django style)

爱⌒轻易说出口 提交于 2019-11-30 05:27:58
I'm using Express JS and I want a functionality similar to Django's reverse function. So if I have a route, for example app.get('/users/:id/:name', function(req, res) { /* some code */ } ) I'd like to use a function for example reverse('/users/:id/:name', 15, 'John'); or even better reverse('/users/:id/:name', { id : 15, name : 'John' }); which will give me the url /users/15/John . Does such function exist? And if not then do you have any ideas how to write such function (considering Express' routing algorithm)? Here is your code: function reverse(url, obj) { return url.replace(/(\/:\w+\??)/g,

Rails optional /:locale route

青春壹個敷衍的年華 提交于 2019-11-30 05:23:51
问题 I'm trying to setup a routing system for my rails app that allows for an optional route (/:locale) to be allowed to the base of the website. So more or less: /en/home/ would goto the same page as /home/ /en/people/ -> /people/ The only issue I'm having is setting this up in the routes config. 回答1: Use scope '(:locale)' do ... end . You can see an example from Agile Web Development with Rails here: http://intertwingly.net/projects/AWDwR4/checkdepot-30/section-15.1.html 回答2: What I usually do

Property 'url' does not exist on type 'Event' for Angular2 NavigationEnd Event

南笙酒味 提交于 2019-11-30 05:17:23
问题 this.subscription = this.router.events.subscribe((event:Event) => { console.log(event.url); ##### Error : Property 'url' does not exist on type 'Event'. } Typescript doesn't recognize the properties of the type Event that is built into the Angular Router. Is there something on tsd that I can use to solve this? Event is the super class of classes NaviagationEnd, NavigationStart 回答1: You have to import { Event } from @angular/router; . Try moving console into the if block with condition. this

Handling freeform GET URL parameters in Play 2 routing

牧云@^-^@ 提交于 2019-11-30 05:14:24
Let's say I have an action that optionally accepts two parameters: def foo(name: String, age: Integer) = Action { // name & age can both be null if not passed } How do I setup my route file to work with any of the following call syntaxes: /foo /foo?name=john /foo?age=18 /foo?name=john&age=18 /foo?authCode=bar&name=john&age=18 // The controller may have other implicit parameters What is the correct syntax for this? Something like this should work: GET /foo controllers.MyController.foo(name: String ?= "", age: Int ?= 0) Since your parameters can be left off you need to provide default values for

MVC routing when a file actually exists at the specified location

拜拜、爱过 提交于 2019-11-30 05:13:28
So I have a route like this in my MVC 3 application running under IIS 7: routes.MapRoute( "VirtualTourConfig", "virtualtour/config.xml", new { controller = "VirtualTour", action = "Config" } ); The trick is that a file actually exists at /virtualtour/config.xml. It seems like the request is just returning the xml file at that location instead of hitting the route, which processes the XML, makes some changes and returns a custom XmlResult. Any suggestions on how I can tell my application to hit the route and not the actual file in the event that the file exists on disk? EDIT: It appears that I

asp.net mvc routing id parameter

只谈情不闲聊 提交于 2019-11-30 05:04:49
I am working on a website in asp.net mvc. I have a route routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); which is the default route. And I have a method public ActionResult ErrorPage(int errorno) { return View(); } Now if I want to run this code with http://something/mycontroller/Errorpage/1 it doesn't work. But if I change the parameter name to id from errorno it works. Is it compulsory to have same parameter name for this method? Or do I need to

Symfony2: How to pass url querystring parameters to controllers?

▼魔方 西西 提交于 2019-11-30 04:47:59
Maybe I am missing something but there doesn't seem to be a way to define querystring parameters in routes in Symfony2 so that they can be passed into a controller. For instance, instead of generating a URI like /blog/my-blog-post (from Symfony2's routing documentation ) and passing it to the following route: # app/config/routing.yml blog_show: pattern: /blog/{slug} defaults: { _controller: AcmeBlogBundle:Blog:show } I would prefer to generate a URI like /blog?slug=my-blog-post . The problem is I can't find anywhere to define the slug parameter in the route configuration file (like its {slug}

Angular 4 routing - redirectTo with skipLocationChange

旧巷老猫 提交于 2019-11-30 04:37:41
问题 I have some routing module with its main path being set as: /canvas const canvasRoutes: Routes = [ { path: "canvas", component: CanvasComponent } ]; @NgModule({ imports: [ RouterModule.forChild(canvasRoutes) ], exports: [ RouterModule ], declarations: [], providers: [] }) export class CanvasRoutingModule { } In the application routing module I would like to have the redirection path set to the /canvas every time the root path is accessed. Currently the configuration looks as follows: const