Heroku Ruby Website Image Uploading Error - ruby-on-rails

Trying to set up image uploading on my website, but whenever I test uploading an image, it fails and I get these errors in the log... I've looked through so many fixes but none seem to work correctly.
If anyone could point me towards a fix or let me know what exactly is going wrong that would be great. Thanks.
2021-04-18T19:33:58.653571+00:00 app[web.1]: [6e2d06ab-891e-4970-8fbe-2e9fb2868eca] ActiveModel::UnknownAttributeError (unknown attribute 'service_name' for ActiveStorage::Blob.):
2021-04-18T19:33:58.653571+00:00 app[web.1]: [6e2d06ab-891e-4970-8fbe-2e9fb2868eca]
2021-04-18T19:33:58.653572+00:00 app[web.1]: [6e2d06ab-891e-4970-8fbe-2e9fb2868eca] app/controllers/gigs_controller.rb:88:in `upload_photo'
2021-04-18T19:33:58.748015+00:00 app[web.1]: I, [2021-04-18T19:33:58.747897 #4] INFO -- : [16714095-28f1-4c97-8e78-407316f869dd] Started GET "/gigs/6/edit?step=4" for [ip address] at 2021-04-18 19:33:58 +0000```

Related

Is there any thing in rails that helps us to know what and all actions are travelled that a route request

I have a huge rails code many routes and i see the console that says for the route home/index
Processing by HomeController#index as HTML
but i don't even see with binding.pry that the route hit but i get 200OK response in my terminal i see that there are many filters being called but i don't know which filter is being called as there are 100's of modules being include.
Is there a formula that guides us telling which page the action has traversed through which module only in the project but not to the internal rails code like traversing inside the rails gem and all.
I get a very white screen on chrome for localhost:3000/ where there is no layout being loaded. So i need to backtrace to what actions has my route hit and what and all callbacks are involved in performing that action.
Its waste of time with binding.pry putting at lots of places.
I, [2019-11-07T13:41:06.046091 #22077] INFO -- : Started GET "/" for 127.0.0.1 at 2019-11-07 13:41:06 +0530
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
W, [2019-11-07T13:41:07.190395 #22077] WARN -- : Creating scope :track_allowed. Overwriting existing method CustomFieldDefinition.track_allowed.
W, [2019-11-07T13:41:07.190553 #22077] WARN -- : Creating scope :document_allowed. Overwriting existing method CustomFieldDefinition.document_allowed.
W, [2019-11-07T13:41:07.190643 #22077] WARN -- : Creating scope :image_allowed. Overwriting existing method CustomFieldDefinition.image_allowed.
W, [2019-11-07T13:41:07.190724 #22077] WARN -- : Creating scope :video_allowed. Overwriting existing method CustomFieldDefinition.video_allowed.
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead.
W, [2019-11-07T13:41:07.325206 #22077] WARN -- : Creating scope :by_ids. Overwriting existing method MediaFormat.by_ids.
I, [2019-11-07T13:41:07.334538 #22077] INFO -- : Processing by HomeController#index as HTML
D, [2019-11-07T13:41:07.336651 #22077] DEBUG -- : Track Load (0.6ms) SELECT "tracks".* FROM "tracks" WHERE (tracks.purged_at IS NULL)
I, [2019-11-07T13:41:07.339979 #22077] INFO -- : Completed 200 OK in 5ms (ActiveRecord: 2.3ms | Path: http://localhost:3000/)
If you are assuming that the / (root path) should hit HomeController#index I think you should check your routes.
A specific url always can only hit one action. In this case your log tells us it is processed by the MainController#home method.
Check your routes (in config/routes.rb) and check your root definition.
It should be
root to: 'home#index'
(and also check if there are multiple occurrences)

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

Ruby on Rails log lines start with "I" or "W"

Noticed that all the lines in Rails log (production.log for example) start with either capital "I" or capital "W". For example
I, [2017-04-04T15:40:40.409423 #15879] INFO -- : [8dd4dd50-2dba-466e-91c3-13e83333db78] Completed 302 Found in 96ms (ActiveRecord: 6.2ms)
I, [2017-04-04T15:40:40.448567 #15866] INFO -- : [e80b7bcc-92be-465a-a9b1-1f39222238cf] Started GET "/bla" for ip at 2017-04-05 15:40:40 +0200
I, [2017-04-04T15:40:40.454994 #15866] INFO -- : [e80b7bcc-92be-465a-a9b1-1f39123138cf] Processing by blaController#index as HTML
Found no explanation for why is it like this and what's the purpose.
It's the standard Logger Format with SeverityID as the first value :
Log format:
SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
Log sample:
I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.

t("website_title") nil after moving from Heroku Bamboo to Cedar

I just moved my working Heroku app from Bamboo to Cedar, and now it crashes with:
Rendered devise/sessions/new.html.erb within layouts/application (4.6ms)
ActionView::Template::Error (no implicit conversion of nil into String):
8: <%= t("website_title") %>
As you can see, t("website_title") seems to be nil, despite the fact that website_title is still in config/locales/en.yml as usual:
en:
website_title: Cats (All about cats)
Is it a known issue when moving from Bamboo to Cedar?
Any idea how to solve it?
Actually, heroku logs was showing log lines in non-chronological order, which lead me to think the problem was line 8, but in fact it was this problem:
https://github.com/rails/rails/issues/9619
Which I solved as explained by dvdplm there.

Not nil code that works for both sqlite3 and pg

I have a rails app running sqlite3 in development and pg in production, currently running on Heroku. I am getting an error on my heroku app. I have a column called 'archived' which starts out as nil until the user pushes a button, then the current time gets written into the cell. Then all messages where archived != nil is then ordered by most recent.
Below is a portion of my heroku log:
2013-05-07T22:00:31.775149+00:00 app[web.1]: Completed 500 Internal Server Error in 34ms
2013-05-07T22:00:31.785541+00:00 app[web.1]:
2013-05-07T22:00:31.785541+00:00 app[web.1]: ActionView::Template::Error (PG::Error: ERROR: invalid input syntax for type timestamp: ""
2013-05-07T22:00:31.785541+00:00 app[web.1]: LINE 1: ... "messages".* FROM "messages" WHERE (archived <> '') ORDER ...
2013-05-07T22:00:31.785541+00:00 app[web.1]: ^
2013-05-07T22:00:31.785541+00:00 app[web.1]: : SELECT "messages".* FROM "messages" WHERE (archived <> '') ORDER BY archived desc LIMIT 10):
This tells me that the issue is this line of code from my controller:
#archived_messages = Message.where("archived <> ''").limit(10).order('archived desc')
What should I change this code to so that it works in both sqlite3 and pg?
Thanks in advance.
Got it!
#archived_messages = Message.where("archived IS NOT NULL").limit(10).order('archived desc')
source: Runs locally with SQLite, but on Heroku: PGError: ERROR: syntax error at or near "NULL"

Resources