routing

How to define a custom path in rails?

六月ゝ 毕业季﹏ 提交于 2019-12-21 04:14:19
问题 I have a User model. If I do: def my_action @user = User.new end then <% form_for(@user) do |f| %> I get undefined method `users_path' for #<ActionView::Base:0x1b4b878> Which make sense because I haven't mapped it going map.resources :users. .. but I don't want to do it this way because I don't need all the resources. How can I just define this user_path method in my routes? 回答1: You can also customize restful routes. For example in my application only the index and show actions are

Can URI templates be used to match URIs to routes?

不羁的心 提交于 2019-12-21 03:51:57
问题 Frameworks like ASP.NET or Nancy provide a syntax that can be used for specifying routes, such as: MapRoute("/customers/{id}/invoices/{invoiceId}", ...) In ASP.NET routes work in two directions. They can match a request URI such as /customers/32/invoices/19 to a route, and they can resolve parameters such as { id: 37, invoiceId: 19 } into a URI. RFC 6570: URI Templates also defines a similar, though much richer, specification for URI's that are often used to resolve URI's. For example:

Rails 3 : route a resource to another name

我的梦境 提交于 2019-12-21 03:14:16
问题 I have a CRUD controller for a model. Doing resources :foo allows me to route on /foo/:id , etc. for calling actions. I want add a route for a translation of 'foo' in another language. Let's say 'toto'. So I want all the /toto/:id , etc., routes to act exactly like the /foo/:id , etc., routes. How may I achieve that? 回答1: You can add a new resource and specify foo as the controller: resources :toto, :controller=>"foo" This will point all the actions to "foo", but there is a gotcha. I think

Can controller names in RESTful routes be optional?

大兔子大兔子 提交于 2019-12-21 02:47:23
问题 With a standard map.resource routing mechanics and several nested resources the resultant routes are unnecessarily long. Consider the following route: site.org/users/pavelshved/blogs/blogging-horror/posts/12345 It's easy to create in routes.rb , and I'm sure it follows some kind of beneficial routing logic. But it's way too long and also seems like it's not intended to be human-readable. A nice improvement would be to drop controller names, so it looks like: site.org/pavelshved/blogging

how to avoid routing through local stack in Linux

纵然是瞬间 提交于 2019-12-21 02:28:11
问题 I have the following environment: 2 hosts, each with 2 Ethernet interfaces connected to eachother (like on diagram below): +---------+ +---------+ | (1)+---------------+(2) | | host1 | | host2 | | | | | | (3)+---------------+(4) | +---------+ +---------+ I would like to write client/server socket tool that will open both client and server sockets on host1. I would like client to send TCP packets through interface (1) and server to listen on interface (3), that packets will go through host2.

Does ServiceStack support reverse routing?

◇◆丶佛笑我妖孽 提交于 2019-12-21 01:06:57
问题 Following REST it is advisable that API is discoverable and should be interlinked. Does ServiceStack support any kind of reverse routing? I'm looking for something like Url.RouteLink in ASP MVC. 回答1: There's some mixed concepts stated here. In and effort of trying to comply with REST you wish to embed URI's in your responses. How best to achieve embedding URI's in your responses. You've assumed a "Reverse Routing" mechanism is how this should be done. REST style vs Strong-typing I want to be

Ember.js routing: how do you set a default route to render immediately?

∥☆過路亽.° 提交于 2019-12-21 00:14:45
问题 I'm sure this will become clear as I dig in deeper, but for now it's not obvious how to make this happen. I was following the info on this helpful SO article about routing but there is an important piece missing from the example, i.e. how do you get the 'home' view to render right away without having to click the 'home' link? I've started digging into the docs to try to make sense of this, but meanwhile it seems like a useful question to have answered for posterity. I've been playing with the

receiving multicast on a server with multiple interfaces (linux)

南笙酒味 提交于 2019-12-20 14:43:44
问题 To receive a multicast on my not default NIC (dvb) I do the following: open a socket (AF_INET, SOCK_DGRAM) join the multicast address with IP_ADD_MEMBERSHIP on the dvb interface bind the multicast address (note that a common error is to bind "0.0.0.0" and then receive on that socket even multicast you are not interested in) and the port at this point the only way to receive the needed multicast packets is to add in the routing table a rule to reach the network where the sender is (another

Rails: Routing subdomain to a resource

南笙酒味 提交于 2019-12-20 13:22:27
问题 Is it possible to map a subdomain to a resource? I have a company model. Currently, using subdomain_fu, my routing file contains: map.company_root '', :controller => 'companies', :action => 'show', :conditions => { :subdomain => /.+/ } My Company model contains a "subdomain" column. Whilst this works as intended, it's a named route and isn't restful. Essentially, I need to map "name.domain.com" to the show action for the companies controller. Is a named route the way to go, or can I use a

ZF2 Routing as in ZF1

被刻印的时光 ゝ 提交于 2019-12-20 10:27:36
问题 How can I make the routing automatically work for everything in the ZF1 structure? module/controller/action/par1Name/par1Val/par2Name/par2Val/ I read the information about routing, but the way I see it, I'd have to add all actions manually, and I see a problem with optional params... 回答1: You can set up a wildcard child_route, at least on a per-controller basis, to get zf1-like routes: 'products' => array( 'type' => 'Zend\Mvc\Router\Http\Segment', 'options' => array( 'route' => '/products[/