custom-routes

global.asax redirecttoroute not working

谁说胖子不能爱 提交于 2019-12-04 12:06:35
I want to use a custom route in my global.asax with response.redirecttoroute but it is not working. I have the following in my RouteConfig: routes.MapRoute( name: "Error", url: "Error/{action}/{excep}", defaults: new { action = "Index", excep = UrlParameter.Optional } ); And in my global.asax I do the following: Response.RedirectToRoute("Error", new { action="Index", excep=ex.Message }); In my ErrorController I have: public ActionResult Index(string excep) { ViewBag.Exception = excep; return View(); } And in my Index view for the error I call the ViewBag.Exception to show the exception. When I

polymorphic_path for custom collection route

て烟熏妆下的殇ゞ 提交于 2019-12-04 06:31:20
I have the following route definition: resources :documents do collection do post :filter end end and the following model structure: class Document < ActiveRecord::Base belongs_to :documentable, :polymorphic => true end class User < ActiveRecord::Base has_many :documents, :as => :documentable end and controller structure: class DocumentsController < ApplicationController def index # not important end def filter # not important end end I can easily in a view say: polymorphic_path([@user, Document]) to get the path /users/1/documents , but I want to be able to say: filter_polymorphic_path([@user

Creating SEO friendly URLs in Rails 3

江枫思渺然 提交于 2019-12-03 13:46:11
问题 I currently have URLs which look like this: things?category_id=6&country_id=17 and I would like to have URLs which look like this: /printer_cartridges/united_kingdom Is there a way in Rails 3, without hard coding all of the categories and countries in the router to have the URLs as I would like above, perhaps using find_by_name or the such like? What is the best way to approach this? 回答1: match '/:category_slug/:country_slug', :to => 'things#index' Then you'll need to update your action to

rails singular resource still plural?

亡梦爱人 提交于 2019-12-03 05:32:13
问题 I have a search route which I would like to make singular but when I specify a singular route it still makes plural controller routes, is this how it's supposed to be? resource :search Gives me search POST /search(.:format) {:action=>"create", :controller=>"searches"} new_search GET /search/new(.:format) {:action=>"new", :controller=>"searches"} edit_search GET /search/edit(.:format) {:action=>"edit", :controller=>"searches"} GET /search(.:format) {:action=>"show", :controller=>"searches"}

Creating SEO friendly URLs in Rails 3

三世轮回 提交于 2019-12-03 04:44:32
I currently have URLs which look like this: things?category_id=6&country_id=17 and I would like to have URLs which look like this: /printer_cartridges/united_kingdom Is there a way in Rails 3, without hard coding all of the categories and countries in the router to have the URLs as I would like above, perhaps using find_by_name or the such like? What is the best way to approach this? match '/:category_slug/:country_slug', :to => 'things#index' Then you'll need to update your action to look up everything using params[:category_slug] and params[:country_slug] instead of the ids. Look at the

rails singular resource still plural?

邮差的信 提交于 2019-12-02 17:54:25
I have a search route which I would like to make singular but when I specify a singular route it still makes plural controller routes, is this how it's supposed to be? resource :search Gives me search POST /search(.:format) {:action=>"create", :controller=>"searches"} new_search GET /search/new(.:format) {:action=>"new", :controller=>"searches"} edit_search GET /search/edit(.:format) {:action=>"edit", :controller=>"searches"} GET /search(.:format) {:action=>"show", :controller=>"searches"} PUT /search(.:format) {:action=>"update", :controller=>"searches"} DELETE /search(.:format) {:action=>

ASP.NET MVC Routes: How to define custom route

谁说胖子不能爱 提交于 2019-11-30 09:18:54
问题 I've looked online for an answer to this question, but I honestly can't seem to find a good reference for MVC routes. I have a UserController for my User objects. One can Edit, Save, View, etc. on the User, so I have actions in that controller to handle each of those. That's all pretty straightforward. But I've recently created a new UserProfile object that one can also edit, view, etc. Rather than create an entirely new controller just for the UserProfile, I'd like to make use of the

Rails 3 Custom Route that takes multiple ids as a parameter

旧巷老猫 提交于 2019-11-30 07:02:46
问题 How do I add a route to my Rails 3 app which allows me to have a URL that maps to an action in a RESTful resource that accepts multiple parameters: /modelname/compare/1234,2938,40395 And then in my controller, I want to access these ids: @modelname = Modelname.find(params[:modelname_ids]) So far, I have been trying match '/modelname/compare/:modelname_ids', :to => 'modelname#compare' , but I keep getting No route matches "/modelname/compare/4df632fd35be357701000005,4df632fd35be357701000005" .

Rails 3 Custom Route that takes multiple ids as a parameter

故事扮演 提交于 2019-11-29 00:17:13
How do I add a route to my Rails 3 app which allows me to have a URL that maps to an action in a RESTful resource that accepts multiple parameters: /modelname/compare/1234,2938,40395 And then in my controller, I want to access these ids: @modelname = Modelname.find(params[:modelname_ids]) So far, I have been trying match '/modelname/compare/:modelname_ids', :to => 'modelname#compare' , but I keep getting No route matches "/modelname/compare/4df632fd35be357701000005,4df632fd35be357701000005" . Any suggestions? You can setup a route that matches anything, then split the parameter inside your

Rails3 Routes - Passing parameter to a member route

隐身守侯 提交于 2019-11-28 22:42:47
I would like to pass an extra parameter to a member route of a resource something like: resources :events do member do get 'register/:participant_type_id' end end I could only accomplish it using a static match statement Looking around the internet I saw that this might be possible in Rails 3.0.2. I'm using 3.0.1 and it certanlly is not. Am I doing something wrong? or is it really not possible? thanks Try this: resources :events do member do get 'register/:participant_type_id', :action => 'register' end end larryzhao Just to complete the answer with my little findings. It also confused me for