What can be reasons of error "None of the chained routers were able to generate route: Route not found" in SymfonyCMF? - symfony-cmf

Getting error from file:
/app/vendor/symfony-cmf/routing/src/ChainRouter.php
"None of the chained routers were able to generate route: Route '/cms/routes/can' not found".
I am guessing it should find this route from database table phpcr_nodes, it exists in database:
but it does not find.
This method call gives this error:
$this->router->generate('/cms/routes/can', array(), RouterInterface::ABSOLUTE_URL)
Where should I look for? How to make it find the route? There does this method look for routes? Maybe I have to add somewhere and it does not even look to database?

Got an answer - it finds route what is in phpcr_nodes.path but somewhere is done a filtering of those rows, by config. So even if the row exists with such route, it does not find because of config. Do not know where that filtering is done but at least for doing current task was enough.
Somebody can append if know how the filtering of phpcr_nodes rows can be done so router does not find them.

Related

Rails routing sometimes replaces the id in url with id-name. How do I avoid problems?

Generally the url from my report page looks like this:
http://test-account.peter:3000/offices/7/reports/index
However, sometimes it looks like this:
http://test-account.peter:3000/offices/7-peters-office/reports/index
Why does this happen?
It was not really a problem until we changed the controller action from a GET to a POST and renamed it. We had to do this so we could pack more parameters in to the ajax request. Users still have this section of the site bookmarked and it throws errors all day long.
I have tried to redirect the route:
get '/offices/*all/reports/index' => 'offices#show'
get '/offices/:office_id/reports/index' => 'offices#show'
get '/offices/:office_name/reports/index' => 'offices#show'
Is there a way to catch the name? Or do I have to prevent the name from being added to the url in the first place?
In the controller, you would be able to parse the parameter to get just the first character and check if its an integer. However, it would be much better to debug how the parameter is getting assigned to different values and ensure only the id is used. If you're linking to that route in a view, check what is being passed in the link and confirm the value is what you expect it to be.
Rails does routing it does not look in your database for matched data. So without looking at data, your three routes are exactly the same, the variable (office_id & office_name) is just named different. If you get a request on example /offices/:office_name/reports/index, rails will just match the first one since both routes match the request.
You need something in the path that indicates its a name or id. If you will really never have a name and id with the same search, then you could just have one route and try to match a id or name from the DB in the controller.

Change route order in Ruby on Rails

I want to have the following URL route in my application: /:username/:resource_name. So, when I type http://www.mywebsite.com/john/apple, it will load the resource called apple that belongs to john. If john or apple don't exist, it will show a message saying that the user or the resource doesn't exist.
When I create that route, it goes to the top of the routes list (rake routes). And in this way, it gets confused with other routes, such as /users/sign_in, and it says that the resource sign_in doesn't exist.
What I want to do is to send my route /:username/:resource_name right to the bottom of the routes list, so it's the last one to be matched. Is that possible, and does it solve my problem? Or is there another way to get this to work?
That's very possible. The routes file is linear - routes defined first take higher precedence over the ones listed later. Just put that route at the bottom of the file.
That should do it since the routing file matches top down. See here for a better explanation: http://guides.rubyonrails.org/routing.html

Strange Rails resource routes behavior

I've met strange error. Im not sure this is bug. However i never met this strange behavior before.
resource :watches
Makes such strange routing table:
watches POST /watches(.:format) watches#create
new_watches GET /watches/new(.:format) watches#new
edit_watches GET /watches/edit(.:format) watches#edit
GET /watches(.:format) watches#show
PUT /watches(.:format) watches#update
DELETE /watches(.:format) watches#destroy
As you see no ID param and messed actions
On same time:
resources :mibs
Make proper routes
mibs GET /mibs(.:format) mibs#index
POST /mibs(.:format) mibs#create
new_mib GET /mibs/new(.:format) mibs#new
edit_mib GET /mibs/:id/edit(.:format) mibs#edit
mib GET /mibs/:id(.:format) mibs#show
PUT /mibs/:id(.:format) mibs#update
DELETE /mibs/:id(.:format) mibs#destroy
I thought that is could be somehow inflector problem, but trying using "rockets" instead of "watches" give same result:
rockets POST /rockets(.:format) rockets#create
new_rockets GET /rockets/new(.:format) rockets#new
edit_rockets GET /rockets/edit(.:format) rockets#edit
GET /rockets(.:format) rockets#show
PUT /rockets(.:format) rockets#update
DELETE /rockets(.:format) rockets#destroy
Anything except my first two resources (servers and mibs) make such result.
Probably corrupted routing cache somewhere?
resource indicates a singleton resource: in other words, you're telling Rails that there's only ever one watch for each user, so passing IDs would be useless.
resources is the standard invocation for getting routes with IDs attached.
So, essentially, the problem is an inflector one, but for resource or resources, not for the name of your routes. For more information, check out the Ruby on Rails routing guide. It does a good job explaining the difference between singleton resources and the more usual kind.

Rails 3 gives routing error with point in URL

I have a search form written with Rails 3 when I query it everything works fine as long as I do not put a point in my query. Eg:
http://localhost:3000/en/job/search/q/test - WORKS
http://localhost:3000/en/job/search/q/test. - DOES NOT WORK
URL with point at the end gives a
Routing Error: No route matches [GET] "/en/job/search/q/test.
Does anybody know how I can solve this? Thanks.
By default, Rails interprets everything to the right of the decimal as the format. You need to set the :constraints
Here is a good article on the subject: http://coding-journal.com/rails-3-routing-parameters-with-dots/
Here is the reference in the Rails API that should help you resolve your issue:
http://guides.rubyonrails.org/routing.html#specifying-constraints
http://guides.rubyonrails.org/routing.html#dynamic-segments
Since your passing a string in the search as a get request, you might also consider route globbing: http://guides.rubyonrails.org/routing.html#route-globbing
Your route would be something like this:
match ":language/job/search/*query"
and in your controller, you would get the value from the route using the params[] array:
q = params[:query]
Be sure to use best practices when passing this to ActiveRecord to avoid a SQL injection attack.
What #iltempo said.
Also, it would be a good idea to switch your search from using GET requests to POST requests to make all these problems go away.

Rails Routing Question: Mapping Slugs/Permalinks Directly under Root?

Morning Everyone!..
General Routing Quesiton Here... I'm currently working to achieve a route similar to this for users in my application.
http://www.example.com/username
This then maps to the usersControllers#show, hence I have the following in my routes file.
map.connect '/:permalink', :controllers => "users", :action => "show"
I've then got the show action to find the user by the permalink in the param. So its works but....
The problem I'm running into is that all other UNDEFINED routes get sent to userController#show. i.e 404's & other un-named routes. So I dont think i'm going with the right convention for this. My solution is to just add other named routes above this, which solves the problem, but to me seems brittle. Am I thinking about this wrong?
Whats a better solution? I'm going to mine google for answers but I just thought i'd throw this up for discussion. Ideas?
You're doing it right. Rails routes go from high priority at the top to low priority at the bottom. Your users show action should go at the bottom. Just make sure that if the permalink does not correspond to a user a proper 404 is generated.
What if you get a user whose username is the same as other URLs on your site?
This seems like a trouble waiting to happen.
Just change it to http://www.example.com/user/username
This way you create a "user" namespace for all username based URLs.

Resources