conflict between websocket url and routes in rails - ruby-on-rails

dear all of master in rails
I am new in developing web app using rails.
Now, i want to try create an app rails using web socket.
I get good tutorial from here
However, when i improve my experience in rails. I get conflict between url websocket and url created in routes.rb
in my routes.rb
get ':username' => 'users#profile', as:"profile"
the url get conflict with url web socket and then, my web app websocket getting failure.
anyone could help me to solve my problem..???
thanks

I fixed this using a routing constraint:
get '/:hash', to: 'conversations#show', constraints: {hash: /((?!websocket).)*/}
The route will not work unless the :hash does not contain the string "websocket"
I'm sure there's a better regex out there, and if my hash ever randomly contains the string "websocket" it'll fail.
But, this fixes your problem for me in development.

What is the error exactly?
You need to change the route
get '/username' => 'users#profile', as:"profile"
I think your should read this

Related

Do I need to change nginx configuration to set up a subdomain for my Rails app?

I am having a problem testing a subdomain for my app. I read in a post that lvh.me will translate into localhost. This has worked well for me in my development environment. I've modified my rails app's routes.rb to have this code:
constraints(Codeopenhub) do
get '/', to: 'codeopenhub#index'
get '/*other', to: 'codeopenhub#index'
end
Basically the code is saying that if you hit code.openhub.net/anything, you'll hit a particular page. Now when I deploy this onto my staging environment, this doesn't work at all. Hitting the subdomain says that the site can't be reached. server DNS address could not be found. Do I need to add an accompanying modification to nginx/sites-enabled or nginx/sites-available? Or perhaps I need an entry in /etc/hosts?
I was following these resources but now I'm a bit stuck and hit a wall. Could someone lend me a hand? It would be greatly appreciated.
Dealing with Subdomains
Capybara and Subdomains

How do I get the route for a path, in a rails application?

Given a method and path, I want to ask Rails how that request would be routed, and i want to be able to do this from console, and/or from a rake task. I figure this should be straightforward - ActionDispatch does this for every request, and the route testing methods obviously also do it.
(Currently: Rails 3.0.x, but for the gem I'm writing I will need to be able to do this in Rails 3.0 through 4.1, at minimum, and possibly in older versions as well.)
I've been trying a few things like this:
routes = ActionDispatch::Routing::RouteSet.new
routes.recognize_path('/my/path/23/edit')
or
Rails.application.routes.recognize_path('/my/path/23/edit')
In both cases, I get back "RuntimeError: route set not finalized".
I'm diving through the ActionDispatch code working it out slowly, but if anyone knows the answer off the top of their head it would save me considerable time. So, thank you!
The canonical answer is actually as given in my question:
# GET request
Rails.application.routes.recognize_path('/some/path/63')
# POST request
Rails.application.routes.recognize_path('/some/path', {:method => :post })
It looks like that wasn't working because I'd previously tried initializing RouteSet manually, which had interfered with the environment's ability to properly load the routes. When I restarted the console session, the above commands worked fine.

Rails routing: Wildcard and german umlauts

I'm just developing a WebDAV interface for a Rails App. Therefor I'm routing all webdav.example.com/path/to/folder paths to a webdav controller:
scope controller: 'webdav', constraints: {subdomain: 'webdav'} do
get '*path', action: 'show'
# some more webdav specific routes...
end
Everything works fine, but for a folder called 'Verträge' the native Windows client now requests webdav.example.com/Vertr%E4ge which unfortunately breaks the rails routing process raising an ActionController::BadRequest...
After some research I figured out that i.e. Gems like HighVoltage have the same problem.
Does anybody has an idea to solve this? Regardless of telling Windows to send a real 'ä' or fixing it at rails side...
UPDATE:
%E4 belongs to ISO-8859-1 (ISO Latin 1) Character Encoding, but Rails routing works with UTF-8.
So GET webdav.example.com/Vertr%C3%A4ge works perfectly fine.
How do I get either Windows to UTF8 encode the urls or Rails to recognize and convert the urls properly before dispatching the request?
Currently ended up patching ActionDispatch::Routing::RouteSet::Dispatcher this way: https://gist.github.com/sdhull/9240273
Other solutions / discussions are welcome :)

No route matches on Rails

I have installed one of my RoR app on my local computer from GitHub.
And trying to have it running on my local machine
But after successful login they throwing me this error which drives me crazy.
I tried to find out solutions, but failed.
Can u guys please explain me possible reasons for this error?
Thanks.
No Route Matches basically means you're trying to load a URL / Route which doesn't exist in your config/routes.rb file
To fix it, you have to look at the request you've sent to Rails & see if it's matched within the routes file. If not, ActionDispatch::Routing will not be able to direct your request to the correct controller / action
You need to give us the actual error & show the routes.rb file to get an accurate answer

Ruby on Rails routing problem

The company that hosts my website did an upgrade on the weekend and now all my ROR apps are coming up with this :
Routing Error
No route matches "/geotest/" with {:method=>:get}
These were working before and do work on my development system, but there has been no response to my ticket to their tech support. Anyone got a suggestion how I could fix this?
Maybe they upgraded to Rails 3 ? Your route should work anyway, but try to add this to your routes.rb file :
get '/geotest' => 'your_controller_name#index'
Change your_controller_name accordingly, of course.

Resources