Rails still throwing error for page that doesn't exist? - ruby-on-rails

I used to have a class Uploads that I later decided to delete. I ran a migration to drop the table, made sure my schema was updated, manually deleted the associated views and controllers, etc. I even ran a grep through my directory to check for traces of "upload" or references to it. However, when I try to access my page I get an error in the console -- 500 Service Error. the log says:
ActionView::MissingTemplate (Missing template /app\views\upload\uploadfile.rhtml with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/Users/claire/Documents/folio/app/views"
* "/Users/claire/Documents/folio"
* "/"
):
app/controllers/upload_controller.rb:3:in `index'
...But neither of those documents exist anymore. I tried clearing my cache and cookies an it has the same effect. What could be causing this?!
My routes.rb file
Folio::Application.routes.draw do
resources :projects
#get "home/index"
root :to => "projects#new"
match 'project/new',:controller=>"projects",:action=>"create"
match "project/:id", :controller => "projects", :action=>"download"
match "projects_controller/filter_list", :controller => "projects", :action => "filter_list"
end

Can you post your routes file? I think the problem is that you still have routes pointing to the deleted controller.

Related

Missing template error for Ruby on Rails Application

I have a view in the LoginController with the following code
def home
render 'home'
end
However, whenever I load my web server, it shows the error message:
ActionView::MissingTemplate (Missing template login/home, application/home with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :jbuilder]}. Searched in:
* "C:/Users/60984/prairielearn-eecs/app/views"
* "C:/Ruby30/lib/ruby/gems/3.0.0/gems/actiontext-6.1.7.2/app/views"
* "C:/Ruby30/lib/ruby/gems/3.0.0/gems/actionmailbox-6.1.7.2/app/views"
):
app/controllers/login_controller.rb:16:in `home'
Even though I have the file in the directory app/views/login/home.html.erb.
I tried changing it to a more specific directory such as
def home
render 'login/home'
end
but it still fails. However, I tried using the whole path like
render file: 'C:/Users/.../app/views/login/home.html.erb'
With the code above, the problem changed into the html.erb is not being interpreted, it will display the code blocks on the browser no matter what browser I use.
I am just confused about why it doesn’t work since I have the html file in the designated place.

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 4 Asset Pipeline link

While using the asset pipeline in production and trying to keep the folder less cluttered, I have set up nested folders. I am trying to link to a pdf within a sub-folder, but I am not sure how to call the file precisely.
<%= link_to ' | PDF', asset_path(pub.file), :target => "_blank" %>
This works in development. For production I will need to call pubfiles/pub.file, but that syntax seems like it is missing something.
I figured out it should be something like this:
<%= link_to ' | PDF', asset_path("pubfiles/#{pub.file}"), :target => "_blank" %>
But when I try to use the link I error out with:
Missing template people/show, application/show with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/rails/neuro/app/views"
def find(*args)
find_all(*args).first || raise(MissingTemplate.new(self, *args))
end
def find_all(path, prefixes = [], *args)
In development without the folder argument setup, the pdf opens without a hitch.
When using asset_path, rails will prepend /assets/ to the path you specified as its argument.
Thus make sure your sub-folder is within assets folder this way:
-public
-assets
-yourFolder
-yourFile.ext
That way, you can use asset_path as asset_path('yourFolder/yourFile.ext') and rails will serve your file at /assets/yourFolder/yourFile.ext
Please notice that rails adds fingerprint to files in order to favor caching. Make sure your assets is properly compiled and configuration for production is properly defined.

Intermittent Ruby on Rails log (ActionView::MissingTemplate)

I keep seeing errors in my logs similar to the below.
Can anyone suggest why I could be getting such an error intermittently? Is it a caching issue?
Every time I attempt to load the about-us page it loads perfectly but every few days there's an error like this in my logs but it's not confined to a single page. Sometimes it's the homepage, some times it's other pages.
Started GET "/about-us" for xxx.xxx.xxx.xxx at 2014-08-16 07:54:06 +0100
Processing by PagesController#about as */*;q=0.6
Geokit is using the domain: mydomain.com
[1m[35mPage Load (0.2ms)[0m SELECT `pages`.* FROM `pages` WHERE `pages`.`name` = 'About Us' LIMIT 1
Completed 500 Internal Server Error in 2ms
ActionView::MissingTemplate (Missing template pages/about, application/about with {:handlers=>[:erb, :builder, :arb], :formats=>["*/*;q=0.6"], :locale=>[:en, :en]}. Searched in:
* "/var/www/myapp/releases/201408150651/app/views"
* "/var/lib/ruby-rvm/gems/ruby-1.9.2-p320/gems/activeadmin-0.3.2/app/views"
* "/var/lib/ruby-rvm/gems/ruby-1.9.2-p320/gems/kaminari-0.12.4/app/views"
* "/var/lib/ruby-rvm/gems/ruby-1.9.2-p320/gems/devise-1.4.7/app/views"
):
This question is similar to: Random rails ActionView::MissingTemplate errors so this is happening to other people but there's no defined answer there either.
You can't prevent this error as there are load reasons(like you mentioned missing cache, unknown request format and etc)
You can try to restrict the number of predefined formats like:
get '/about-us' => 'controller#about', :format => /(?:|html|json)/
Also you can suppress this exception. Create a new file(for example exception_handler.rb) in the directory config/initializers and Add this line into created file:
ActionDispatch::ExceptionWrapper.rescue_responses.merge! 'ActionView::MissingTemplate' => :not_found
Hope it helps.
#ProblemSolvers is a possible solution. However, I added the following method in my application_controller.rb file so that such errors will render a 404 page rather failing with a error message on screen
rescue_from ActionView::MissingTemplate, :with => :rescue_not_found
protected
def rescue_not_found
Rails.logger.warn "Redirect to 404, Error: ActionView::MissingTemplate"
redirect_to '/404' #or your 404 page
end
you can wrap this code in a if statement, something like this if Rails.env.production? given that the env is setup so your dev environment wont be affected

Rails App: Missing template with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>["image/jpeg", "image/pjpeg", "image/png", "image/gif"]}

My rails app uses a route called "four_oh_four" to provide a custom 404 page that uses the site's application layout to look nice.
I've started receiving the following errors:
Missing template info/four_oh_four with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>["image/jpeg", "image/pjpeg", "image/png", "image/gif"], :locale=>[:en, :en]}
I can't seem to figure out what I need to be doing to resolve this. Any ideas?
Here's what the controller looks like (nothing, really):
def four_oh_four
end
And here's the routes.rb:
match 'four_oh_four' => 'info#four_oh_four', :as => :four_oh_four
...
# Catch 404s
match '*path' => 'info#four_oh_four', :status => 404
You can check if there is a file named "four_oh_four.html.erb" in your info dir. It could be mistyping error . Usually the 404 page is located in /public .

Resources