routes

How to override Rails app routes from an engine?

左心房为你撑大大i 提交于 2019-12-21 17:14:37
问题 I have a Rails app that I am trying to integrate a Rails engine in to. The host app has some catch all routes: # magic urls match '/' => 'admin/rendering#show' match '*path/edit' => 'admin/rendering#show', :defaults => { :editing => true } match '*path' => 'admin/rendering#show' It looks like the engine routes are loaded after the application catches all routes. /sitemap.xml(.:format) {:format=>"xml", :controller=>"admin/sitemaps", :action=>"show"} /(.:format) {:controller=>"admin/rendering",

Ruby on Rails Passing Parameter In URL

百般思念 提交于 2019-12-21 13:05:20
问题 This is probably a very simple fix but I've been unable to find an answer just yet. My application has orders and tasks. Orders have many tasks. When a user clicks new task in the show order view, it passes the order.id: <%= link_to "New Task", new_task_path(:order_id=> @order.id) %> The url shows: /tasks/new?order_id=1 I just don't know how to extract this and use it in my form? I have tried: <%= f.text_field :order_id, :value => @order_id %> But it's not working. 回答1: You can do: <%= f.text

How do ASP.NET MVC Routes work?

自作多情 提交于 2019-12-21 12:41:07
问题 I have the following route's defined: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" } ); // Added custom route here! routes.MapRoute( "CatchAll", "{*catchall}," new { controller = "Error", action = "NotFound" } ); } nothing new - that's the default ASP.NET MVC1 RegisterRoutes method, with one custom route added. Now, if

Handling route errors in ASP.NET MVC

北城余情 提交于 2019-12-21 12:18:37
问题 I understand how to set up my own routes, but how does one handle routes that fall through the cracks of the routing table? I mean, I guess the default {controller}/{action}/{id} route could be a generic catchall, but I'm not sure if that's the way to go. I like letting my users know they've requested data/a 'page' that doesn't exist. Is this where the [HandleError] filter comes in? How does that work, exactly? 回答1: If your route is not found, you want to handle it as a normal HTTP 404 error.

MVC4 - Is there a way to route the root to a “normal” unprocessed html page?

我是研究僧i 提交于 2019-12-21 07:56:16
问题 I have an MVC4 app, but I'm primarily using it for the WebAPI parts. I want to have a "plain old HTML" file sent back to the user (which will then use KnockoutJS or KendoUI to pull JSON from the webapi controllers). I know I can do this: routes.IgnoreRoute("{page}.html"); And then if I browse to "localhost/index.html" it does successfully just return my .html page. However, I really want to map the "root" default path "localhost/" to return my index.html. I tried this: routes.MapPageRoute(

MVC - RouteLink and Image

旧街凉风 提交于 2019-12-21 07:35:37
问题 I'd like this output: <a href="\Catalog\Flooring"> <img src="http://site.com/dot.jpg" width="100px" height="100px" alt="" /> <span>Some text here</span> </a> using a RouteLink similar to: <%= Html.RouteLink(myFPV.ProductTypeName, "CatalogType", new { controller = "Catalog", action = "Types", group = myFPV.ProductGroupName, type = myFPV.ProductTypeName })%> I cannot figure out how to add an <img> and <span> (with text) tags inside my <a> tag. Make sense? 回答1: The first parameter of the

ASP.NET MVC routing by string id?

孤街醉人 提交于 2019-12-21 07:23:12
问题 In ASP.NET 2, how do I create a route that allows lookup of an object (eg Product) by a string id (eg ProductCode)? The route for looking up the same object by it's integer id (eg ProductId) is automatic, so I don't actually know how it works. The automatic route by id is: /Product/1 How do I also create a 2nd route that uses a string id? /Product/red-widget And how do I do it so that both routes are available? 回答1: You should take a look at using a route constraint to do this. See http://www

RESTful design, how to name pages outside CRUD et al?

可紊 提交于 2019-12-21 07:13:10
问题 I'm working on a site that has quite a few pages that fall outside my limited understanding of RESTful design, which is essentially: Create, Read, Update, Delete, Show, List Here's the question: what is a good system for labeling actions/routes when a page doesn't neatly fall into CRUD/show/list? Some of my pages have info about multiple tables at once. I am building a site that gives some customers a 'home base' after they log on. It does NOT give them any information about themselves so it

Rails 3 nested resources short name?

早过忘川 提交于 2019-12-21 04:41:06
问题 I'm in the process of upgrading a Rails 2.3 app to Rails 3. In the Rails 2.3 router, it was possible to set a :name_prefix of nil on nested resources to get a shorter name. The actual URL would still be fully qualified, but the code could use a shorter name. E.g.,: map.resources :sites do |site| site.resources :groups, :as => :groups, :controller => :url_groups, :name_prefix => nil, :member => { :clone => :post } do |group| group.resources :tests, :as => :tests, :controller => :test_runs,

How to send an array via a URI using Attribute Routing in Web API?

删除回忆录丶 提交于 2019-12-21 04:04:34
问题 I'm following the article on Attribute Routing in Web API 2 to try to send an array via URI: [HttpPost("api/set/copy/{ids}")] public HttpResponseMessage CopySet([FromUri]int[] ids) This was working when using convention-based routing: http://localhost:24144/api/set/copy/?ids=1&ids=2&ids=3 But with attribute routing it is no longer working - I get 404 not found. If I try this: http://localhost:24144/api/set/copy/1 Then it works - I get an array with one element. How do I use attribute routing