path not recognized by Rails - ruby-on-rails

My app is calling a resource trougth a path helper show_popular_hashtags_path, but Rails seems to not recognize it. This is my partial:
.col-xs-12.no-padding.blue-title{style: "page-break-inside: avoid !important;"}
.col-xs-12.text-center.global-map.no-padding
%h1
= t('uniq.hashtag.title')
.js-column-chart-hashtags{data: {url: show_popular_hashtags_path(id: #project.id, provider: provider), provider: provider}}
.column-chart-hashtags.statistics-chart{class: "#{provider}", style: "width: 100%"}
%h2.empty-message.column-chart-hashtags{class: "#{provider}", style: "padding-top: 15px; padding-bottom: 30px; display: none;"}
= t('unique.there_is_no_info')
this is my routes.rb:
namespace :user do
resources :projects, except: [:delete] do
member do
get :show_users, to: 'projects#js_show_users_data', as: :show_users_data
get :show_popular_hashtags, to: 'projects#js_show_popular_hashtags', as: :show_popular_hashtags
get :show_activity_data, to: 'projects#js_show_activity_data', as: :show_activity_data
For the another routes everything goes very well, even when I run rake routes | grep show_popular_hashtags, the output is:
$ rake routes | grep show_popular_hashtags
show_popular_hashtags_user_project GET /user/projects/:id/show_popular_hashtags(.:format) user/projects#js_show_popular_hashtags
So, this looks like the route is well, but when I visit the view which contains the partial this error appears:
undefined method `show_popular_hashtags_path' for #<#<Class:0x007fa20d865d10>:0x007fa20dc5a6f0>
I already restarted the server, but it did not work.

The name of your routes helper is actually show_popular_hashtags_user_project, not show_popular_hashtags. You can see it in the first column of the rake routes output:
$ rake routes | grep show_popular_hashtags
show_popular_hashtags_user_project GET /user/projects/:id/show_popular_hashtags(.:format) user/projects#js_show_popular_hashtags
Just change the name of the show_popular_hashtags routes helper to show_popular_hashtags_user_project in your view, and it will work.

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.

Ruby on rails multi level route path

I have defined a route as per the below but I am getting some errors. Below is the code outlining what is happening
namespace :shopping do
resources :merchants, only: [:index, :show] do
Which I was hoping I would be able to use = link_to shopping_merchant_path(merchant)
But this is giving me the following error
No route matches {:action=>"show", :controller=>"shopping/merchants", :id=>nil, :locale=>#<Merchant id: 1, name: "52e9689bc89a", featured: false>} missing required keys: [:id]
rake routes output
Pauls-Air% rake routes | grep shopping_merchant
shopping_merchant_products GET (/:locale)/shopping/merchants/:merchant_id/products(.:format) shopping/products#index {:locale=>/en/}
shopping_merchant_product GET (/:locale)/shopping/merchants/:merchant_id/products/:id(.:format) shopping/products#show {:locale=>/en/}
shopping_merchants GET (/:locale)/shopping/merchants(.:format) shopping/merchants#index {:locale=>/en/}
shopping_merchant GET (/:locale)/shopping/merchants/:id(.:format) shopping/merchants#show {:locale=>/en/}
As onikron suggested you need to pass parameter to your route
= link_to shopping_merchant_path(#merchant)
I think you are trying something like
= link_to shopping_merchant_path(locale: #merchant)
:locale=>#< Merchant id: 1, name: "52e9689bc89a", featured: false>
No need of :locale in link_to

No route matches [GET] "/users/assets/bootstrap.min.js" only in Firefox?

Firefox gives me this error when i try to sign in or sign up into my app, i am only working locally and i am using devise gem for this. After loading the form it cracks into this routing. The file bootstrap.min.js is in the stylesheets folder and into assets folder. In the layouts i have declared:
<script src="assets/bootstrap.min.js"></script>
Chrome and Safari does not have any problem. Another strange behavoir, i guess related to the same issue, is that when i try to inspect element it falls into this error:
No route matches [GET] "/assets/bootstrap.min.css.map"
The Routes file is done like this:
Rails.application.routes.draw do
resources :properties
devise_for :users
root "properties#index"
get "about" => "pages#about"
get "user_properties" => "pages#user_properties"
get "contact" => "pages#contact"
Anyone have a clue?
try this:
<script src="/assets/bootstrap.min.js"></script>

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.

Rails 3 & Sinatra integration issue

I am trying to set up a sinatra app inside my Rails 3 (v3.0.1) application, but having no success. Sinatra gem (v1.1.0) is setup using bundle install.
Here's what i have.
customer_app.rb class in lib directory -
class CustomerApp < Sinatra::Base
get "/test" do
"Hello World"
end
end
my routes.rb file contains -
CustomerService::Application.routes.draw do
root :to => CustomerApp
end
The URL i am trying is - http://localhost:3000/test
I get this error (on the browser) - Routing Error. No route matches "/test"
and this error in the log - ActionController::RoutingError (No route matches "/test"):
Is there anything I am missing??
Also I just noticed, even a simple rack route is not working -
root :to => proc { |env| [200, {}, ["Welcome!"]]}
The root keyword by default maps only the path /.
So you are trying to say, forward any request for / to CustomerApp which can handle requests for /test.
You should change the match filter.
CustomerService::Application.routes.draw do
match "/test" :to => CustomerApp
end

Resources