Rails Routing help - ruby-on-rails

I have the following in my routes.rb:
match "/profile/permissions" => 'profiles#edit_permissions', :as => 'edit_permissions', :via => :get
match "/profile/permissions" => 'profiles#update_permissions', :as => 'update_permissions', :via => :post
Getting /profile/permissions works find, yet, when I post to /profile/permissions, I get:
Started POST "/profile/permissions" for 127.0.0.1 at 2011-03-29 12:12:09 -0400
ActionController::RoutingError (No route matches "/profile/permissions"):
Any ideas?

Can you put your routes.rb in a gist? Sometimes there's a conflict, and extra eyes are needed to find it. Also, for the sake of fidgeting, you might try out the new shorthand:
get "/profile/permissions" => 'profiles#edit_permissions', :as => 'edit_permissions'
post "/profile/permissions" => 'profiles#update_permissions', :as => 'update_permissions'
Unto themselves, both your routing text and this example successfully trigger their actions on the specified controller.
Start a test app, with only a routing file, run its server, and try to post to those URLs. If you want to use the Rails console, check out this.
> require "uri"
> require "net/http"
> url = app.update_permissions_url
> url = "http://localhost/profile/permissions" (if your domain is bollocks)
> Net::HTTP.post_form(URI.parse(url),{})
Easy to minimalize your environment for testing, now.

Related

RoR, Sizzle Uncaught Error: Syntax error, unrecognized expression: /sv/priser

The error
jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:1464 Uncaught Error: Syntax error, unrecognized expression: /sv/priser
at Function.Sizzle.error (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:1464)
at Sizzle.tokenize (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:2121)
at Sizzle.select (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:2542)
at Function.Sizzle [as find] (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:865)
at jQuery.fn.init.find (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:2788)
at new jQuery.fn.init (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:2905)
at jQuery (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:76)
at HTMLAnchorElement.<anonymous> (kontakt:50)
at HTMLAnchorElement.dispatch (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:4733)
at HTMLAnchorElement.elemData.handle (jquery.self-977e28a4e7fded7698789e394a585c6339d54c0ad1537f498a40d2800098a521.js?body=1:4545)
Getting this error when clicking on a to_link tag in RoR v.5.2 (Ruby v2.5)
The link works, and takes me to the targeted html.erb file. I can't find any solution that has worked.
The tag the error occurs for all tags like this, this one is just an example.
<%= link_to 'Prices', en_prices_path, :class => "page-scroll", id: 'prices' %>
My routes
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
namespace :en do
get 'index' => 'pages#index', as: 'home'
get 'prices' => 'pages#prices'
get 'about' => 'pages#about'
get 'contact' => 'pages#contact'
end
namespace :sv do
root 'pages#index', as: 'home'
get 'priser' => 'pages#priser'
get 'om' => 'pages#om'
get 'kontakt' => 'pages#kontakt'
end
get '*path' => redirect('/sv')
end
Its noteworthy to mention that the link exists in a partial _nav file that that is being rendered into an index or contact.html.erb file amongst others, that is then being rendered into the application.html.erb file.
I hear talk about jquery complaining about bad selectors, which makes me believe the paths (for example sv_priser_path) the router gives me is bad (it gives me /sv/priser). Can i edit them perhaps? Would that stop the error from happening? I tried parsing them with
$($.parseHTML(sv_priser_path)[1]
but that i didnt get that to work either. Didnt get a replace script to work either to remove the slash.

Rails Engine not routing in webpage

I am trying to mount a rails engine piggybak_paypal.
Inside my application's config/routes.rb file I add
mount PiggybakPaypal::Engine => '/paypal', :as => 'piggybak_paypal'
and the engines route is like this
PiggybakPaypal::Engine.routes.draw do
get "/express" => "paypal#express", :as => :paypal_express
get "/process" => "paypal#process_express", :as => :paypal_process
end
When I try rake routes the route of the engine is showing correctly
Routes for PiggybakPaypal::Engine:
paypal_express GET /express(.:format) piggybak_paypal/paypal#express
paypal_process GET /process(.:format) piggybak_paypal/paypal#process_express
but when I open my website and use /express the server cannot find the route
ActionController::RoutingError (No route matches [GET] "/express"):
I've look around but I can't find a solution to it.
okay I just figure out why the routing is not working and I can't believe I spend hours on this and didn't found out why.
All I did is change the route from
mount PiggybakPaypal::Engine => '/paypal', :as => 'piggybak_paypal'
to
mount PiggybakPaypal::Engine => '/', :as => 'piggybak_paypal'
then /express works.

Url redirection issue in nginx -AmazonEc2 server

I am getting an issue.
We have created a new website for our site using angularJs and ruby on rails.I am using amazon EC2 for hosting purpose.I have used thin and nginx as webserver and application server respectively.
I have made changes in the nginx.conf file and have written redirection rules.However I am having an issue while implementing the same.
While going to TV guide from a website,the url it is showing is :-
http://www.abc.com/WhatsOnTV/Star_world/Boston-legal.aspx?Time=140220141300
It is redirecting me to:-
http://apps.abc.com/WhatsOnTV/Program/Boston_legal.aspx
Whereas it should have landed on:-
abc.com/program/Boston-Legal
This is happening because of the the config file in which I have written the rule(which cannot be removed as we require it ):-
rewrite (?i)^/WhatsOnTV(.*) http://apps.abc.com/WhatsOnTV$1 permanent;
Also another issue I am facing is that the url encoding is different for both.In the old site the space in programs was encoded with _ and in our current site it is encoded with -
My rails routes are the following:-
WoiWeb::Application.routes.draw do
get "appi/index"
get "appi/reco"
get "appi/auto"
get "appi/tsm"
get "appi/user"
get "myaccount/index"
post "myaccount/create"
get "socialfeed/index"
get "myprofile/index"
get "discussion/home"
get "discussion/newdiscussion"
get "sitemap/index"
get "privacy/index"
get "tnc/index"
get "corporate/index"
get "contact/index"
get "about/index"
get "apps/index"
get "videos/index"
get "movies/index"
get "pop_up/show"
get "watchlistsocial/index"
get "favourites/index"
get "reminders/index"
get "channels" => "channel#index"
get "channels/details" => "channel#details"
get "home" => "home#index"
get "languages" => "languages#index"
get "genre" => "genre#index"
get "languages/accounts" => "languages#accounts"
get "programme" => "programme#index"
get "programme/info" => "programme#info"
get "search" => "search#index"
get "movies" => "movies#index"
get "videos" => "videos#index"
get "apps" => "apps#index"
get "tv-guide" => "tv-guide#index"
get "tv-guide/calendar" => "tv-guide#calendar"
get "tv-guide/tvoperator" => "tv-guide#tvoperator"
get "tv-guide/accountstvoperator" => "tv-guide#accountstvoperator"
get "pop-up/show" => "pop-up#show"
get "pop-up/genre" => "pop-up#genre"
get "pop-up/showChannelGenre" => "pop-up#showChannelGenre"
get "pop-up/showRating" => "pop-up#rating"
get "pop-up/reminder" => "pop-up#reminder"
get "user/signin" => "user#signin"
get "user/signup" => "user#signup"
get "user/forgot-password" => "user#forgotPassword"
get "user/popup_login" => "user#popup_login"
get "user/beforeaction" => "user#beforeaction"
get "user/watchlist" => "user#watchlist"
get "user/reminders" => "user#reminders"
get "verify/index" => "verify#index"
get "watchlist" => "watchlist#index"
get "watchlistinfo" => "watchlist#info"
get "movies/popover" => "movies#popover"
get "watchlist/calendar" => "watchlist#calendar"
get "ip" => "ip#index"
get "actor/profile" => "actor#profile"
get "productions" => "productions#index"
get "crawler/crawlhome" => 'crawler#crawlhome'
get "crawler/crawlprogram" => 'crawler#crawlprogram'
get "crawler/crawlchannel" => 'crawler#crawlchannel'
get "crawler/crawlchannels" => 'crawler#crawlchannels'
get "crawler/crawlactor" => 'crawler#crawlactor'
get "crawler/crawltvlistings" => 'crawler#crawltvlistings'
get "crawler/crawlmovies" => 'crawler#crawlmovies'
get "crawler/crawlvideos" => 'crawler#crawlvideos'
get "crawler/crawlmobileapps" => 'crawler#crawlmobileapps'
get "videos/sitemap" => 'videos#sitemap'
So I am stuck with this.Can someone please suggest me some way to tackle this.
Also want to know if it would be better just to make changes in the backend if it's a better option
Your question is confusing. Are you landing to abc.com or to apps.abc.com? In below regex its forwarding to the abc.com
rewrite (?i)^/.*/(.*?)\.aspx\? ht tp://abc.com/program/$1 permanent;
replace ht tp as http from above.

ActionDispatch::Http::Parameters#encode_params tries to modify frozen strings and raises on upgrade from Rails 3.0 to Rails 3.2.16

Basically, this seems to be https://github.com/rails/rails/issues/7725 reported a year ago by a guy who stopped responding (heh http://xkcd.com/979/)
and I got this when upgrading from the very last Rails 3.0 to Rails 3.2.16.
The route in question serves HTML from model Page on routes of form /en/contact for example (from config/routes.rb)
# pages
STATIC_PAGES.each do |slug, desc|
match ":language/#{slug}" => 'pages#static_page', :defaults => {:slug => slug, :language => 'en'}, :via => :get, :as => slug.underscore.to_s
end
My attempts to make a sample application that does the same thing and breaks have failed (copied relevant parts of the app into a new app, copied the Gemfile & Gemfile.lock and tried to reproduce, all went fine)
This is the stack trace: https://gist.github.com/bbozo/8315184 - not a single line from my app in it
Again, it's one of those argh, a ghost issues, if anyone has a hunch where to hunt for it, you'll make me VERY happy
:-/
Duping the key from hash iterator fixed it for me,
# pages
STATIC_PAGES.each do |slug, desc|
match ":language/#{slug}" => 'pages#static_page', :defaults => {:slug => slug.dup, :language => 'en'}, :via => :get, :as => slug.underscore.to_s
end
problem here was that STATIC_PAGES is a hash constant with String keys, it's keys are frozen. In cases of requests for which route defaults kicked in the router tried to do something with the frozen slug string stored in :defaults => {:slug => slug - something in the rails 3.0 => rails 3.2.16 changelog introduced a modification of this value and shiny exceptions happened in the ActionDispatch stack.
"Unfreezing" slug by doing slag.dup fixed the issue

rspec chokes on named path in rails 3

Re-writing a photography portfolio site, and urls have to follow the format:
[site].com/portfolio/[category]/[image]
to match current implementation.
[site].com and [site].com/portfolio should resolve to the root. my routes file is below:
root :to => 'portfolio#index'
match '/portfolio', :to => 'portfolio#index'
match '/portfolio/*category/*photo', :to => 'portfolio#photo'
match '/portfolio/*category', :to => 'portfolio#photo'
I added a link in my header to:
%li= link_to "Portfolio", root_path
and this works fine, but when I add:
%li= link_to "Editorial", portfolio_photo_path
my pages resolve fine in-browser, but rspec chokes out on me; even the simplest http success tests that would previously run fine now return:
1) PortfolioController GET 'index' returns http success
Failure/Error: get 'index'
ActionView::Template::Error:
undefined local variable or method `portfolio_photo_path' for #<#<Class:0x572d210>:0x5733d68>
# ./app/views/layouts/_header.html.haml:7:in `_app_views_layouts__header_html_haml__420220390_28357236'
# ./app/views/layouts/application.html.haml:10:in `_app_views_layouts_application_html_haml__156489427_30065868'
# ./spec/controllers/portfolio_controller_spec.rb:8:in `block (3 levels) in <top (required)>'
(when I rake routes, i get the following)
$ rake routes
root / portfolio#index
portfolio /portfolio(.:format) portfolio#index
/portfolio/*category/*photo(.:format) portfolio#photo
/portfolio/*category(.:format) portfolio#photo
You should add ":as => :portfolio" statement:
match '/portfolio', :to => 'portfolio#index', :as => :portfolio
Answered in my comment above; I'd defined variable-globbed routes, and brain-fartedly didn't realize that i'd have to construct the links directly and dynamically.

Resources