Slim template can't be rendered on production - ruby-on-rails

I did update my application to Rails 4.1.10 and it works fine on my staging environment.
Now as soon as I deploy my App to production I get the following fatal error in one of my views:
F, [2015-03-26T18:12:21.159599 #4741] FATAL -- :
ActionView::Template::Error (795: unexpected token at [[iI""$2a$10$2BUwvWEvQzm404VPpY71BO:ET'):
5: .row
6: .col-xs-8
7: h1 = search_highlight(#programme.title, params)
8: - if current_admin_user
9: i.fa.fa-edit
10: '
11: = link_to t('edit'), (admin_programme_path(#programme) + '/edit'), target: '_blank'
app/views/programmes/show.html.slim:8:in `_app_views_programmes_show_html_slim__2487450803659794271_70344829653360'
The hint I get is very misleading and I can't seem to figure out what is wrong here.
795: unexpected token at [[iI""$2a$10$2BUwvWEvQzm404VPpY71BO:ET'

It turned out that the issue was not directly related to slim at all. When I access current_admin_user then the cookies from the client were parsed and since I did upgrade my Rails app from 4.0 to 4.1 the cookies were stored in the old format and the default for Rails 4.1 is :json.
So changing the following setting from :json to :hybrid in cookies_serializer.rb did the trick
Rails.application.config.action_dispatch.cookies_serializer = :hybrid

Related

"no implicit conversion of nil into String"in the Search Module of Redmine

On the redmine of my company, there is this bug where I get an internal error if I want to search into a project.
Here is the log corresponding to the error:
Processing by SearchController#index as HTML
Parameters: {"utf8"=>"✓", "issues"=>"1", "q"=>"test", "id"=>"sprint"}
Current user: me (id=60)
Completed 500 Internal Server Error in 85.0ms
TypeError (no implicit conversion of nil into String):
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb:126:in `search'
app/controllers/search_controller.rb:74:in `block in index'
app/controllers/search_controller.rb:73:in `each'
app/controllers/search_controller.rb:73:in `index'
The lines corresponding to the error in the controller are :
if !#tokens.empty?
# no more than 5 tokens to search for
#tokens.slice! 5..-1 if #tokens.size > 5
#results = []
#results_by_type = Hash.new {|h,k| h[k] = 0}
limit = 10
#scope.each do |s|
r, c = s.singularize.camelcase.constantize.search(#tokens, projects_to_search,
:all_words => #all_words,
:titles_only => #titles_only,
:limit => (limit+1),
:offset => offset,
:before => params[:previous].nil?)
#results += r
Here is my config :
Environment:
Redmine version 2.6.9.stable
Ruby version 2.3.0-p0 (2015-12-25) [x86_64-linux]
Rails version 3.2.22
Environment production
Database adapter PostgreSQL
SCM:
Git 1.9.1
Filesystem
Redmine plugins:
no plugin installed
What is interesting is that when I search only one letter, i'm redirected on the search page, but I don't have an internal error.
I'm very new to Redmine developpement and to Ruby, I was just assigned to try to fix this bug. Do any of you have an idea of how to fix it ?
Thanks.
I had the same issue, I was able to fix it by downgrading my ruby & rails version, a working set is :
Rails 3.2.19
Ruby 2.1.4p265
It's look like it's due to a braking change in ruby-2.3.0.
It's really odd. We are using 'Redmine' -2.0.3.1 and we do not have that kind of behaviour.
It seems that "someone" messed up the form linked to the search input. Try to follow that data from when you press enter until it answer you with the 500 error code.
If you can , change the environment to development, this way it will show you more detailed errors.
But I can't help you much more , you didn't provide enough info about the problem.

How to run Ruby on Rails 3 with ruby 2.0

Is there an easy fix, how I could continue an old rails 3-0.20 installation under ruby 2.0?
The first error, caused by this line:
<%= stylesheet_link_tag :all %>
is
ActionView::Template::Error (no implicit conversion of nil into String):
An upgrade of the rails version would be the best, but unfortunately it is not possible in my case.
Hotfix the problem with the following line at the end in application.rb
ActionController::Base.config.relative_url_root = ''
I ran into the same issue. After drilling down into the stylesheet_link_tag method, I found that the issue comes from here
# actionpack-3.0.20/lib/action_view/helpers/asset_tag_helper.rb:749
if has_request && include_host && !source.start_with?(controller.config.relative_url_root)
The problem is String#starts_with?. In 1.9.3, that method will handle a nil as an input. 2.0.0 does not allow that.
ruby-1.9.3> 'whatever'.start_with? nil
=> false
ruby-2.0.0> 'whatever'.start_with? nil
TypeError: no implicit conversion of nil into String
It's probably also true that later versions of Rails set the value to '' if it's not set to prevent this issue. The hotfix mentioned above does fix the issue, but the root cause is differences between 1.9.3 and 2.0.0.

Rails Ruby - Handeling Nil in production vs development

I launched my site with phusion passenger on a server and everything seems to run smoothly exept one page.
Here I get the following error message:
NoMethodError in Identities#show
Showing /var/www/feedme/app/views/identities/_platemenu.html.erb where line #13 raised:
undefined method `collect' for nil:NilClass
10: <div id="plate_heading_box">
11: <p class="plates_head">
12:
13: <%#params=#myp.collect{|i| i.to_i}%>
14: <%#allsecondary=#plates.collect(&:id)%>
15:
16: <%if #startup != 1%>
It seems like the instance variable #myp doesn't work in production, because it works perfectly fine when I test it on my own computer in development. The variable is first declared in my controller:
if params[:plates]!=nil
#myp = params[:plates]
else
#myp = Array.new
end
Not really sure why it doesn't work, any clues?
Thanks in advance!
EDIT:
If I move the controller code out to the view it works... I wish the site would read the controller first ....
I suspect the problem is actually on line 14, where you call collect on #plates, which doesn't appear to be initialized anywhere.

Extremely rare haml error

I'm currently trying to deploy an Ruby on Rails 3.0.9 app on a production server. Everything seems to be going fine untill passenger gives an 'We're sorry, but something went wrong.' error upon requesting the website.
The production log shows this error:
Rendered sessions/new.html.haml within layouts/application (5.7ms)
Completed 500 Internal Server Error in 8ms
ActionView::Template::Error (syntax error on line 7, col 7: `'):
2: %h2 Sign in
3: = form_for( :sessions, :url => sessions_path) do |f|
4: .field
5: = f.label :email
6: %br/
7: = f.text_field :email
8: .field
app/views/sessions/new.html.haml:5:in
_app_views_sessions_new_html_haml__1068828667_250539460_0'
app/views/sessions/new.html.haml:3:in
_app_views_sessions_new_html_haml__1068828667_250539460_0'
*Edit: Removing the f.label :email and f.label :password rows makes this error disappear, but this obviously isn't a fix *
Some information about this error:
I develop with aptana on windows
A co-developer who works with this project on a mac, was subject to this error a while ago, but fixed this with some unknown magic with gemsets and rvm.
Bundle list of the production server: http://pastie.org/private/0itpfmbfwqvhpheptqz4ha
Github repository: http://github.com/boersmamarcel/Into-Reality-Portal
I'm deploying with capistrano 2.0 and the bundle recipe for it
A similar error also happens on other views, but somehow this error also points to line 7 of the file, and the error message sometimes shows random strings after
col 7:
I can't manage the global gemset on the production server
Weird fact: If I remove the = f.label :password and = f.label :email rows, the error is gone :s
I would be very grateful if someone could help me with this. We have been working on this error for the whole day and it's driving me nuts.
Thanks
- Bas
Edit: the f.label function seems to be causing the problem. I uploaded a trimmed down version of the view which generated the following error:
http://pastie.org/private/cqqipdvqod3r50x9ciwytq
This application runs succesfully on other mac-based and windows-based computers.
If you copied the above exactly, what is the %br doing with a trailing slash? If you're rending this in HTML (not XHTML) the trailing slash is no longer valid. I don't know if it matters but sometimes the slash character throws off HAML in strange ways for me.
After puzzling with this error for hours and hours, it turned out the I18n gem caused this problem.
I had a unclosed entity in my en.yml which looked like this:
en:
time:
formats:
hourminute: "%H:%M"
date:
Removing the date: part fixed this -in my opinion- very obscure error
Thanks to all the people who used their braincycles on this problem :)!

Puzzled by Rails exception notification system

[update2] One of those problems I solved & can't remember how... :)
[update1] could this be a problem in the model?
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
The page I'm trying to access on my site is the cart page for paypal purchases. Notwithstanding the trouble of getting to this error in the production log amidst an apparent DoS attack, I have no experience working with the exception notifier. What's being called (by my code) is an encryption method in the model for each 'buy now' button. Please help me diagnose the problem.
Rendering .../public/500.html (500 Error)
rendering section "request"
/!\ FAILSAFE /!\ Fri Jan 16 14:59:54 +0000 2009
Status: 500 Internal Server Error
ActionView::TemplateError (protected method `filter_parameters' called for #<PurchaseController:0x7f053d26e280>) on line #3 of vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml:
1: * URL : <%= #request.protocol %><%= #host %><%= #request.request_uri %>
2: * IP address: <%= #request.env["HTTP_X_FORWARDED_FOR"] || #request.env["REMOTE_ADDR"] %>
3: * Parameters: <%= filter_sensitive_post_data_parameters(#request.parameters).inspect %>
4: * Rails root: <%= #rails_root %>
If you are using a "later" version of rails, you probably need to make this change: http://www.floydprice.com/2008/08/exception-notifier-in-rails-21/
The ActionView::TemplateError you've posted is caused by a failure of Exception Notifier in rendering a 500 error page (line #3 of Exception Notifier's own _request.html partial). The more interesting exception is probably the one that came before and caused the 500 in the first place.
Not an answer to your question, but something that will help.
I've recently come to love the Hoptoad gem and site for grouping and reporting exceptions with my app in production. Extremely easy to install and no more trawling through my production logs.
I say switch to this from excpetion notification and see if it helps.

Resources