Rails Ruby - Handeling Nil in production vs development - ruby-on-rails

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.

Related

Rails 5.2, Erratic "Unable to autoload constant": sometimes it works, sometimes not

I have a view that ajax-loads the same partial a number of times. Each one contains the result of a rather extensive calculation which takes a number of seconds. On my machine, about 3 times out of 20, instead of the partial I get the error message "Unable to autoload constant Answers::Node::Questions::KurzSinglePunch... expected .../app/models/answers/node/questions/kurz_single_punch.rb to define it" (I shortened the text and the path for legibility). The file is obviously there, since in 17 of 20 cases it is found, and the partial displays correctly in these cases.
In case this is relevant, I use Puma in single mode on a six-year-old Mac running OS 11.6.
This is the topmost part of the error message:
LoadError in KurzReportsController#company Unable to autoload constant Answers::Node::Questions::KurzSinglePunch,
expected /Users/marion/Documents/Projekte/myproject/app/models/answers/node/questions/kurz_single_punch.rb to define it
Extracted source (around line #511):
#509 else
#510 require_or_load(expanded, qualified_name)
*511 raise LoadError,
"Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
#512 return from_mod.const_get(const_name)
#513 end
#514 elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
Extracted source (around line #195):
#193 def const_missing(const_name)
#194 from_mod = anonymous? ? guess_for_anonymous(const_name) : self
*195 Dependencies.load_missing_constant(from_mod, const_name)
#196 end
#197
#198 #
We assume that the name of the module reflects the nesting
Extracted source (around line #285):
#283 constant.const_get(name)
#284 else
*285 candidate = constant.const_get(name)
#286 next candidate if constant.const_defined?(name, false)
#287 next candidate unless Object.const_defined?(name)
#288 Rails.root: /Users/marion/Documents/Projekte/myproject
Application Trace app/exporters/kurz_report_extractor.rb:63:
in `infos_for_question_id' app/exporters/kurz_report_extractor.rb:59:
in `block in build_survey_hash' app/exporters/kurz_report_extractor.rb:59:
in `map' app/exporters/kurz_report_extractor.rb:59:
in `build_survey_hash' app/exporters/kurz_report_extractor.rb:15:
in `initialize' app/controllers/kurz_reports_controller.rb:27:
in `new' app/controllers/kurz_reports_controller.rb:27:
in `block in company' app/controllers/kurz_reports_controller.rb:25:
in `each' app/controllers/kurz_reports_controller.rb:25:in `company'
After that there is a long section with a Framework trace.
How can it be that Rails is sometimes unable to find this file? And how can I fix this?

I am building a simple kivy app to display datatables and this part of the code raises an error. Are there any fixes?

Building a basic app the shows tables. But this simple code isn't working for me.
self.data_table = MDDataTable(column_data=[("col2",dp(30)),("col2",dp(30))],row_data=[("row 1.1", "row 1.2")])
self.add_widget(self.data_table)
It keeps showing me the following error:
BuilderException: Parser: File "<inline>", line 20:
18: radius: [self.border_radius]
19: source: root.background
20: md_bg_color: self.theme_cls.bg_light
AttributeError: 'str' object has no attribute 'bg_light'
Any idea on why this is happening?

undefined method `+' for nil:NilClass in sample saml application

Trying to follow the setup here to create a simple SAML application (full project I got here).
I went through and did the setup
bundle install
rails s
This went fine, but when I navigate to
http://localhost:3000/
I get hit with
NoMethodError in SamlController#init
undefined method `+' for nil:NilClass
Extracted source (around line #9):
def init
request = OneLogin::RubySaml::Authrequest.new
direct_to(request.create(saml_settings))
end
def consume
I added some logging to check nil status of request and saml_settings but that seems to return false for both of them
puts request.nil?
puts saml_settings.nil?
Error trace:
Processing by SamlController#init as HTML
false
false
Created AuthnRequest: <samlp:AuthnRequest AssertionConsumerServiceURL='http://localhost:3000/saml/consume' ID='_394fa0a0-f313-0135-85a4-6a0001e18280' IssueInstant='2018-02-13T17:42:45Z' Version='2.0' xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion' xmlns:samlp='urn:oasis:names:tc:SAML:2.0:protocol'><saml:Issuer>http://localhost:3000/saml/consume</saml:Issuer></samlp:AuthnRequest>
Completed 500 Internal Server Error in 15ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `+' for nil:NilClass):
app/controllers/saml_controller.rb:9:in `init'
(Note: the error is line 5, it says line 9 for me because of debug logging I added)
I'm not too sure what else it could be, not sure what method it can't find and what is nil?
I have never messed with ruby stuff, but from my initial looks I'm not sure where the nil is coming from, the logs show the request being created so not sure. Any help would be appreciated, thanks!
Firstly I think you're using a pretty old ruby-saml gem version. That might be the problem.
I haven't tested your code, but it seems to me that you forgot to set idp_sso_target_url in your settings, and apparently that's the only place it can throw the exception you got. https://github.com/onelogin/ruby-saml/blob/v1.1.2/lib/onelogin/ruby-saml/authrequest.rb#L39
Posting the answer here, turns out that i was using a metadata url for the OKTA_METADATA environment variable.
Had to modify
settings = idp_metadata_parser.parse(ENV['OKTA_METADATA'])
to
settings = idp_metadata_parser.parse_remote(ENV['OKTA_METADATA'])
where
OKTA_METADATA=http://blahblahblah.com/metadata

Slim template can't be rendered on production

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

How to Calculate Nothing - Nil on Rails

Rails 4, Spree 2.1
The Issue:
Adding an item to cart with the Spree Flexi Variants engraving calculator, I get an error:
undefined method `value' for nil:NilClass
Is this line in my engraving calculator model causing this error?
def compute(product_customization, variant=nil)
return 0 unless valid_configuration? product_customization
# expecting only one CustomizedProductOption
opt = product_customization.customized_product_options.detect {|cpo| cpo.customizable_product_option.name == "inscription" } rescue ''
opt.value.length * (preferred_price_per_letter || 0)
end
def valid_configuration?(product_customization)
true
end
And as for the value method, any ideas on that?
I've tried defining value but nothing seems to work. I have another calculator called amount times contant. This is setup pretty much the same way; however, this one works. Getting kind of confused and way past my deadline.
Here is the github repo with the branch that I am using: https://github.com/jsqu99/spree_flexi_variants/tree/spree-2-1-wip
Trace:
NoMethodError (undefined method `value' for nil:NilClass)
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/calculator/engraving.rb:29:in `compute'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/product_customization.rb:11:in `price'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `block in add_to_line_item'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `map'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:32:in `add_to_line_item'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_contents_decorator.rb:7:in `add'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:36:in `attempt_cart_add'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:17:in `block in populate'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:16:in `each'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/models/spree/order_populator_decorator.rb:16:in `populate'
/Users/russellkompinski/Desktop/spree_commerce/spree_flexi_variants/app/controllers/spree/orders_controller_decorator.rb:18:in `populate'
The source code you pointed to on github contains a different definition of compute as follows:
which is consistent with your stack trace, since line 29 of engraving.rb involves an invocation of value. I'm not familiar with spree, but based on this code, the detect call is returning nil.

Resources