Rails NoMethodError when converting strings to date from submitted form - ruby-on-rails

Rails 4.0.3. I have a form with a date field. In other words, it only works when I just use date_select. that works perfectly on my dev machine. When I deploy it to production, the form refuses to submit and throws a NoMethodError upon reaching the date, complaining about the lack of the utc method. I can't trace it because the production server's log never tells me more than the line where it fails, but that line is the Model.new(params[:form]) line and the failure is during the type conversion magic.
The field is currently a text field with the value supplied by jQuery UI datepicker, but this problem exists also when it is a plain Rails formhelper date_field. As soon as it gets to the date, it fails... but it works perfectly in dev and I'm deploying to production using Git, so I know we are on the same page.
Locally, I'm working in jRuby and using Neo4j.rb 2.3 as my DB. I have mimicked the dev environment by running the production app server, Torquebox, and it still local, fails remote. I'm running the same version of jRuby in both locations and I have all of my gems locked to specific versions to rule out some weird version-specific bug. Any thoughts are very appreciated!

Try this code and see if it works:-
date_string = "#{review_params['date(1i)']}-#{review_params['date(2i)']}-#{review_params['date(3i)']}"
#concert = Concert.find_or_create_by!(artist: review_params[:artist], venue: review_params[:venue], date: date_string)

I realized the solution AS SOON AS I was clicking the submit button but wanted to document this in case someone else ever has this issue. This is actually a bug in the neo4j-wrapper gem... that had a pull request merged two months ago... that I wrote. And I forgot about it. My local gemset still had my modified version of the gem cached, I guess, but the server was just using the latest release, which was done before my modification went in.
This bug is in type_converters.rb. Neo4j saves all times and dates to the DB as integers so it needs to convert whatever is submitted. The original code checked the type of the object to be converted. If it was a date, it converted it to a time and then ran utc; else, it just ran utc. This is obviously no good for strings, so my fix ran Time.parse(s) first.
So, if anyone else is having this issue and is using Neo4j.rb 2.3, add this line to your gemfile
gem 'neo4j-wrapper', git: 'https://github.com/andreasronge/neo4j-wrapper', ref: '00e5665ead'

Related

Ruby on Rails link generated with link_to helper no longer works in Chrome

Chrome has been making a lot of changes recently, and one of them has broken a code statement I use to retrieve a document stored in a database, related to a parent record. The action to upload the file and create the attachment relationship is working, so my users can still add documents. They can no longer download and view stored document attachments. The code is using the link_to helper method, and appears to be building the link correctly, verified by the fact that it still works using Edge, so my users have an ugly workaround, but I need to understand what is happening. I have confirmed that it is indeed Chrome that is the problem, because at first I couldn't recreate the defect in development (until I updated my Chrome browser to current version.) Now I can recreate the defect in my development environment.
When the link in my form is clicked, Chrome displays an error screen with this text:
This page isn't working
(*localhost*) sent an invalid response
net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
If I extract the link using developer tools and try and execute it in an empty browser window, I get the same error.
The link is constructed like this:
(*name of the file attachment*)
Before you ask, yes, I have confirmed there are no commas or quotes in my file names! lol
I am hoping someone somewhere can point me to a solution, hopefully simple, maybe obvious, that I can use to get my web form to play nicely with Chrome again - application code change, web server configuration (I am running on RHEL7 Apache in production and Puma in development, my database is Oracle, and I am building with Ruby 2.3.6 and Rails 5.1.5, along with many many gems).
I hope I have covered all the relevant points. Thank you for taking the time to read this post!
Issue has been resolved by upgrading gem attach to version >= 1.0.5. Many thanks to the gem author for excellent responsiveness.

jazz_hands gem breaks history in rails console

I've started using jazz_hands to make my Rails console more useful, but now line/history editing is broken. When I run over the end of the line (ie, wrap), or use up arrow to go into history, the output is garbled.
Terminal settings are fine for everything else, Ubuntu 12. Any ideas? I'm hoping it's something simple and I'm not the first developer to bump into this, but there's nothing in the FAQ, or in the various related Gems (pry etc), and I'm loathe to raise a bug on the project until I check this isn't a well known issue.
It's fixed in the latest update, but here's a few workarounds if for some reason you can't update.
https://github.com/nixme/jazz_hands/issues/1

How do I acess/open/edit a .sqlite33 file?

I'm completely new to Ruby on Rails, have never worked on it, but I am supposed to take over somebody else's old project. He designed a webapp that logs into a website/server online, extracts data from it daily and performs calculations. However, the application has not been running for quite some time, so now when it tries to display statistics, the page crashes. It uses data from a 5 week period and currently only has data for 2 days.
I need to manually insert data for the missing weeks in order to get it up and running again, but the problem is I don't know how to find/access its database, nor how exactly to use Ruby on Rails. I found several files in the db directory of his project, however they were mostly .sqlite33 files or just 'files'. I downloaded sqlite precompiled binary for Windows and tried to use it, but not sure what to do. I also downloaded and tried using SQTView to open the files to change the tables, but I have had no luck.
How can I tell which file is the main database and how do I edit it? And what are .sqlite33 files? Thanks.
EDIT
The application produces a
TypeError in HomeController#index
"nil can't be coerced into Float"
It links the error to a line in the code, but the only reason the error happens is because there is no data in the table for the time period that the variable in this line of code tries to use. That is why I want to manually update it with values.
I think that Sqliteman might do the trick and thank-you for explaining all of this to me. I just have to confirm it works after editing.
EDIT2
Okay, so I had a small revelation while experimenting on his app. It turned out that the page crashed because of empty values for full weeks. If I used the app to gather data for at least one day per week up until this week, then the app worked.
Is there a way I can populate all the missing days without having to manually click the days in its calendar because it takes a good 20-30 seconds for it to load?
Thank you very much for your help.
A Rails application's database is defined in config/database.yml - though the database itself and the scheme are in the db folder. In database.yml you'll find three database configurations - development, test and production - so make sure to choose the right file.
I've never heard of .sqlite33 files, but to edit SQLite files manually I recommend SQLiteMan. But I don't recommend editing it manually.
What I do recommend is to check if you are running the app in development or production mode, as the two mods use different databases. Try to run it in the other mode.
If that doesn't work, try saving a copy of the database files, and running the commands:
bundle install
bundle exec rake assets:precompile
rake db:migrate
rake db:migrate RAILS_ENV="production"
(if you're using Linux, you might want to also run the first command with sudo)
Those commands make sure all the required gems are installed, that the precompiled assets are up to date, and that the database fits the schema. If you are running that application on the same machine and with the same database as the ones the other guy was using, than those commands shouldn't be necessary, but if you have moved the application to your own machine, or used an used an outdated db file, than those commands might fix the crash.
At any rate, if you tell us what error the application is producing we might be able to provide more assistance.

Turn on html_safe for the entire app in Rails 3

Rails 3 turns off the html_safe option by default. I want to revert this thing. I have a rails 2.3.8 app getting converted to rails 3. Almost every page breaks because of the rails3 default html_safe setting. Is there any way I can revert this to where it was in previous versions of rails ? Please help
No, there isn't and even if there is, you shouldn't.
It's a good habit to test (and update) your app using the rails_xss plugin in Rails 2.3.x before actually starting the conversion to Rails 3.
Also, you should have a valid test suite in place so that every error will be spotted by the test suite and you can easily fix it.
Don't try to upgrade unless you have completed these two simple steps. There are also a few other suggestions.
As a side note: Current versions of Rails 3 HTML-escape also non-HTML templates, which is a bug. See: https://rails.lighthouseapp.com/projects/8994/tickets/4858
I'm posting this here, because I found this question while investigating the bug mentioned above, but didn't fine that ticket or anything about this bug on the interwebs. (Bad google skills?) Hope it saves someone time.

Rails Tests Fail With Sqlite3

I seem to be getting a strange error when I run my tests in rails, they are all failing for the same reason and none of the online documentation seems particularly helpful in regards to this particular error:
SQLite3::SQLException: cannot rollback - no transaction is active
This error is crippling my ability to test my application and seems to have appeared suddenly. I have the latest version of sqlite3 (3.6.2), the latest sqlite3-ruby (1.2.4) gem and the latest rails (2.1.1).
Check http://dev.rubyonrails.org/ticket/4403 which shows a workaround. Could that be the problem you are encountering?
I had this problem once but with MySQL. Turned out I hadn't created the test database. Doh! Rails and sqlite creates them automatically I believe (at least it does in windows).
Are trying to do in memory testing? If not does the test database exist?
I got this error when running a test with the last statement being a click on a form submit. Once I did an assertion or should test, the test closed properly, and I didn't have to rerun the rake db:test:prepare
Thanks for the help. I actually ended up just deleting the rails folder and checking back out the last working copy from version control. I've made the identical changes and this problem hasn't reappeared, so either I messed up or rails had some sort of hiccup. Thankfully I had version control :-)

Resources