Tag Archives: routes

Route Parameters – AngularJS

Hey everyone,

This is just a quick post on what I did to get my routes working properly with AngularJS. My routes looked like this:

//Configure routes
app.config(function ($routeProvider) {
    $routeProvider
		//...
        .when('/Businesses/Details/:id', {
            templateUrl: '/Businesses/Details'
        })
        //...
	.otherwise({
	    redirectTo: '/'
	});
});

And then to access the ID parameter I used $routeParams:

 
/* Used to display the lesson planner for customers */
app.controller("CustomerPlannerController", function ($scope, $routeParams /*, ... */) {
     console.log($routeParams);
     console.log($routeParams.id);
}

Using that setup, a route to /Businesses/Details/:id will display the following output in the console:

//Route to: /Businesses/Details/:id
Object {id: "1"} 
1

Note that you can call ID whatever you want, just make sure you change your route to match. Hopefully that’ll be enough to get you going, but if you have any issues check out these links:
http://stackoverflow.com/a/11064503/522859
http://docs.angularjs.org/api/ngRoute.$routeParams

Devise Overriding Controller Route – Ruby on Rails

I ran into a bit of a problem today after implementing a search form that appeared on every page. When the login page was loaded I received the following error:

No route matches {:controller=>”devise/products”, :method=>:get, :action=>”search”}

The weird thing about this is that the route my search form uses does not mention devise in any way:

<%= form_tag :controller => 'products', :action => 'search', :method => :get do %>

As you have probably already guessed, I’m using devise to handle my authentication. Unfortunately this seems to be overriding some of my routes whenever it co-exists with another form. Luckily there exists a very simple, although hard to find solution – simply add a forward slash before the controller definition:

<%= form_tag :controller => '/products', :action => 'search', :method => :get do %>

Here’s a quick link to the StackOverflow post which gave the answer, hopefully a few more links to it will make it a little easier to find for anyone else out there doing a search!

Error 324 (net::ERR_EMPTY_RESPONSE) – Ruby on Rails

I managed to break my app again while playing around with the routes and a few redirects:

No data received
Unable to load the webpage because the server sent no data.
Here are some suggestions:
Reload this webpage later.
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

 

This wasn’t one I had encountered before and unfortunately Google couldn’t give me anything to cheat off. Luckily, a quick review of the server log revealed the following message just before it closed the connection:

[2011-12-03 21:09:05] ERROR URI::InvalidURIError: the scheme http does not accept registry part: 192.168.1.3:3000locations (or bad hostname?)

 

From this error message it became clear that I needed to place a forward slash before my redirect path:

1
2
#Redirect to edit location path      
redirect_to '/locations/edit'

 

Hopefully this’ll be able to help someone else out there, Good Luck!

Routing Error – No Route Matches [Post] “orders/new”

I ran into a fairly common routing error this morning, thankfully these are fairly easy to fix – usually!

Routing Error
No route matches [POST] “/orders/new”

Simply add the following the route to your routes.rb file:

\site\config\routes.rb

#Orders
controller :orders do
post ‘orders/new’ => ‘orders#new’
end

You may also have to restart WEBrick for this new route to take affect. Good Luck!