routing

Rails 3 routing: Avoiding Deep Nesting

别等时光非礼了梦想. 提交于 2019-12-01 01:14:27
问题 Today I realised I'd gotten a little carried away with nested resources: resources :organisations do resources :studies do resources :settings end end The Rails guidelines (and my own thoughts) suggest that you shouldn't nest more than 1 level deep, so I refactored to this: resources :organisations do resources :studies end resources :studies do resources :settings end Does anyone know a cleaner / more concise way to declare the above routes? Google gave me a lot of Rails 2-specific stuff.

Rails RSpec Routing: Testing actions in :except do NOT route

↘锁芯ラ 提交于 2019-12-01 01:09:52
问题 Fairly simple problem (I'd have thought), but I'm having some issues: In Rails 3.1.0.rc6/RSpec 2.6.0, I'm trying to test the routing of my 'products' resource, routed like this: resources :products, :except => [:edit, :update] The routing for the valid actions works, but I want to ensure that the edit and update routes are not callable. Here's what I'm trying: it "does not route to #edit" do lambda { get("/products/1/edit") }.should raise_error end Failure/Error: lambda { get("/products/1

Routing in Rails making the Username an URL:

强颜欢笑 提交于 2019-12-01 01:09:29
In my Rails App there is Device Model - User, and a Registry model( Each user has one registry). I wanted to change my routes so that instead of: "http://localhost:3000/registries/3" it shows: "http://localhost:3000/erinwalker" So I changed routes to match '/:name' => "registries#show" And the show action in my controller to: def show @user = current_user @user = User.find_by_name!(params[:name]) @registry = @user.registry And it works, but when I create or update the registry now first it says: Couldn't find User with name = app/controllers/registries_controller.rb:21:in `show' Even though

In Symfony 2, how do I handle routing for multiple domains?

雨燕双飞 提交于 2019-12-01 00:55:41
I have my app setup to use 3 subdomains, I also have 2 domains that point to the same app, giving me this set of FQDNs admin.domain1.com, admin.domain2.com www.domain1.com, www.domain2.com kiosk.domain1.com, kiosk.domain2.com In routing.yml I can set up the host / resource keys to point those domains at the relevant bundle, but I can only do it for one of the domains at a time. incompass_admin: host: admin.domain1.com resource: "@IncompassAdminBundle/Resources/config/routes.yml" incompass_web: host: www.domain1.com resource: "@IncompassWebBundle/Resources/config/routes.yml" incompass_kiosk:

Can you explain the Functionality of requestRouteToHost() in android?

人盡茶涼 提交于 2019-12-01 00:08:37
In my code I am using requestRouteToHost() method: Does this routing means changing the WIFI to 3G or vice versa?? My code is not working... public static boolean isHostAvailable(Context context, String urlString) throws UnknownHostException, MalformedURLException { boolean ret = false; int networkType = ConnectivityManager.TYPE_WIFI; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if(cm != null){ NetworkInfo nf = cm.getActiveNetworkInfo(); if(nf != null){ networkType = nf.getType(); } URL url = new URL(urlString); InetAddress iAddress =

routing error with :username in url

﹥>﹥吖頭↗ 提交于 2019-12-01 00:05:27
I have a Rails 3 question. I want to get my users controller show page to have the app.com/people/username url. Route resources :users match "/people/:username" => 'users#show', :as => :profile It's work, but if username starts with "." (dot) I have an error: No route matches "/people/.G" And <%= link_to current_user.username, profile_path(current_user.username) %> raise an exception: No route matches {:controller=>"users", :action=>"show", :username=>".G"} Sorry for my English, Thanks! I don't think starting with . is supported by default in rails routes. You can do something like match "

In ASP.NET MVC 2 - How do I get Route Values into my navigation controller so I can highlight the current link?

被刻印的时光 ゝ 提交于 2019-11-30 23:54:38
I'm trying to get the current Route into my navigation controller so I can run comparisons as the navigation menu data is populated. My Links object is like this: public class StreamNavLinks { public string Text { get; set; } public RouteValueDictionary RouteValues { get; set; } public bool IsSelected { get; set; } } In the master page, I'm trying to pass the current route to the nav controller like this: <% Html.RenderAction( "MenuOfStreamEntries", // action "Nav", // controller new { // parameters for action currentStreamUrl = "Blog", currentRoute = ViewContext.RouteData } // get route data

How to redirect (301) when changed routing translation?

走远了吗. 提交于 2019-11-30 23:54:02
I am looking for an easy way to make redirects in my application. SITUATION: I have routes like this: http://myapp.com/authors/5-hemingway/books/1-moby-dick The routes are translated this way (using gem 'i18n_routing'): http://myapp.com/acutores/5-hemingway/libros/1-moby-dick Now, I changed translation of acutores to scriptores. Easy step but I'd like to redirect all routes that contained an old "acutores" resource name to routes with "scriptores" instead. My guess is, I should play in routes.rb with: match "/acutores" => redirect("/scriptores") But how to do it efficiently for all cases where

Url routing with database lookup?

末鹿安然 提交于 2019-11-30 23:52:09
I want to build a ASP.NET MVC site so that the controller for a specific url is stored in the database instead of the URL. The reason for that is that i'm building a CMS system and the users should be able to change the template (controller) without changing the URL. I also think that the name of the controller is not relevant for the end users and i want clean URL:s. I realise that i could just add all routes at application start, but for a system with like 100 000 pages it feels like a bad idea. Is it possible to store the url:s in the database and make a lookup for each request and then map

nested form_for singular resource

浪尽此生 提交于 2019-11-30 23:49:01
I have a singular nested resource like so: map.resources :bookings, :member => { :rate => :post } do |booking| booking.resource :review end Giving me these routes: new_booking_review GET /bookings/:booking_id/review/new(.:format) {:controller=>"reviews", :action=>"new"} edit_booking_review GET /bookings/:booking_id/review/edit(.:format) {:controller=>"reviews", :action=>"edit"} booking_review GET /bookings/:booking_id/review(.:format) {:controller=>"reviews", :action=>"show"} PUT /bookings/:booking_id/review(.:format) {:controller=>"reviews", :action=>"update"} DELETE /bookings/:booking_id