routes

No route matches although there is one in rake routes

南笙酒味 提交于 2019-12-08 21:03:57
问题 I get strange ActionController::RoutingError: No route matches . The route can be generated: > r = Rails.application.routes > r.generate controller: :items, action: :index, user_id:1 => ["/users/1/items", {}] And it is in the rake routes : $ rake routes user_items GET /users/:user_id/items(.:format) items#index POST /users/:user_id/items(.:format) items#create new_user_item GET /users/:user_id/items/new(.:format) items#new edit_user_item GET /users/:user_id/items/:id/edit(.:format) items#edit

Dealing with Alias URLs in CakePHP

好久不见. 提交于 2019-12-08 20:06:32
I am rewriting our company website in cakephp, and need to find a way to do the following: A user enters our site by using one of the promotional alias URLS that has been pregenerated for a specific media advert ( magazine, web promotion etc ) The URL is checked against a database of alias URLs, and if an alias exists, then a specific tracking code is written into the session. I have considered several options, none of which seem suitable for this purpose. They are: Putting the lookup script in the beforeFilter() in appcontroller, so that its included in every controller. (Writes a session

Rails routes.rb syntax

百般思念 提交于 2019-12-08 19:28:54
问题 I have searched and searched and I cannot find a page which spells out the syntax of routes.rb in Rails 3. There are guidelines, overviews, even advanced examples but why isn't there a page that spells out the exact syntax of each keyword?? This page http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/ contains a lot of advanced examples but doesn't take the time to discuss the behavior of all the examples given. I would appreciate it if someone could point me to a page that

Rails routes, url and subdomains

夙愿已清 提交于 2019-12-08 19:08:38
问题 My ruby app is divided in different namespaces. like: free(free.domain.com), pro(pro.domain.com), vip(vip.domain.com) In the routes file looks like this: namespace :free do match 'home' => 'free#home', :via => [:get, :post], :as => :home #more routes end namespace :pro do match 'home' => 'pro#home', :via => [:get, :post], :as => :home #more routes end namespace :vip do match 'home' => 'vip#home', :via => [:get, :post], :as => :home #more routes end match '/about' => 'pages#about' match '/team

can I read/write the routing table in C without using system() command?

白昼怎懂夜的黑 提交于 2019-12-08 17:39:53
问题 I have code written in C. I want to get using C code information that is stored in routing table. Is it possible? 回答1: You can open a netlink socket and send route update messages. There is an article about how to do this. 回答2: You can also run "strace route add ..." to see how the route command does it. On my system, it uses ioctl with SIOCADDRT . A little searching turns up some sample code. Oddly, the best documentation I have found is from IBM's AS400 man pages. If you just want to read

How to reload a route using hasher.js and crossroads.js?

不打扰是莪最后的温柔 提交于 2019-12-08 17:36:25
I currently have this code: crossroads.addRoute('/login', function(){ $.ajax({ url: '/login', type: 'GET', data: { }, success: function(msg) { $('#' + main_window).html(msg); } }) }); Along with this hasher.js for maintaining history: function parseHash(newHash, oldHash){ crossroads.parse(newHash); } hasher.initialized.add(parseHash); //parse initial hash hasher.changed.add(parseHash); //parse hash changes hasher.init(); //start listening for history change $('a').on('click', function(e) { e.preventDefault(); hasher.setHash($(this).attr('href')); }); Now when I have a link that says #/login

Laravel define a put/patch route as the same route name

瘦欲@ 提交于 2019-12-08 17:32:22
问题 In Laravel it's quite handy to quickly generate a load of routes by using a route resource: Route::resource('things'ThingsController'); This will produce all the necessary RESTful routes for CRUD operations. One of these is the PUT/PATCH route which might be defined as follows: PUT/PATCH things/{id} ThingsController@update things.update I've read around that it's better to explicitly define each of your routes rather than use a route resource but how would I define the PUT/PATCH route above.

Redirecting from routes when the constraints fail

送分小仙女□ 提交于 2019-12-08 17:28:10
问题 I want to redirect to a different url when the route constraint fails Route.rb match '/u' => 'user#signin', :constraints => BlacklistDomain blacklist_domain.rb class BlacklistDomain BANNED_DOMAINS = ['domain1.com', 'domain2.com'] def matches?(request) if BANNED_DOMAINS.include?(request.host) ## I WANT TO REDIRECT HERE WHEN THE CONDITION FAILS else return true end end end 回答1: Because Rails routes are executed sequentially, you can mimic conditional login in the following manner: # config

What is the best way in Rails to determine if two (or more) given URLs (as strings or hash options) are equal?

扶醉桌前 提交于 2019-12-08 17:25:21
问题 I'm wanting a method called same_url? that will return true if the passed in URLs are equal. The passed in URLs might be either params options hash or strings. same_url?({:controller => :foo, :action => :bar}, "http://www.example.com/foo/bar") # => true The Rails Framework helper current_page? seems like a good starting point but I'd like to pass in an arbitrary number of URLs. As an added bonus It would be good if a hash of params to exclude from the comparison could be passed in. So a

Rails 3 Routing - How to use scope to create admin prefix

独自空忆成欢 提交于 2019-12-08 17:11:33
问题 I'm using this Rails Guide to create a scope in order to create an "/admin" prefix for some controllers. So I have a controller named Pages, I want to access it via "/admin/pages". scope "/admin" do resources :pages end That works great, but it is still accessible via "/pages" ... How do I prevent that? (I'm using Rails 3) Here's my routes file: devise_for :users scope "/admin" do resources :pages resources :contents end root :to => "index#index" match ':controller(/:action(/:id(.:format)))'