On my company's Rails website, we have a Twitter area where tweets from our social media team are displayed by a rake task. Basically the rake task uses the Twitter gem to import any new tweets into the database on a regular basis, and displays them from there. URL links in the tweet are converted to HTML links using the auto_link helper.
Always works fine, until now. All of the sudden, the links are broken and even wrongly highlighting the word right before the URL link. So in an example tweet that should look like this: "Please be safe St. Louis. Heat warning extended through August http://bit.ly/...", the word August is linked and the URL itself that follows is broken, as if there was something in between the last word and link breaking it...
Investigated the helpers, looked in the database for the tweet's text field to see if there was anything strange, even used the rails console to manually pull up the tweets, but everything looked okay. It wasn't until I went all the way into the tweet body's hex code that I saw...
Please be safe S
t. Louis. Heat w
arning extended
through August.
 http://bit.ly/
r5fXlz #heatpoca
lypse
So the culprit was that   being thrown into the space, when I deleted the culprit space and readded it manually in the database, the issue cleared up.
The only problem is, I don't understand why the tweet body is being imported like that, especially when it looks fine via the Rails console. As this is an older database, I noticed it was still using latin1 encoding in some areas with utf8 in others, and I was certain that converting all of that to UTF-8 would fix it, but it did not.
I went as far as tried to use a sanitation helper on the body before being imported, but that didn't work either.
Also tried a ruby gsub to strip the   out, but it didn't work.
Does anyone have any insight on how to solve this odd problem?
I was finally able to solve this by running the following specifically on the body string in the rake task...
Iconv.conv('ASCII//TRANSLIT', 'UTF8', tweet.body)
Odd, but it works. More information on using the above can be found here: ruby (1.8.7): How to get rid of non-printable chars while scraping?
Related
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.
I am working with the Salesforce Ruby API which has a pretty good, but slightly dated set up guide. After installing the right gems it says to enter 'script/console' into the command line, and then enter '>> Salesforce::Contact.first' which should respond with a user id.
I have read other's post saying that script/console is no longer being used and to use rails console instead. That works fine, but when I enter '>> Salesforce::Contact.first' it complains that the syntax is wrong.
I also tried removing the >> from the front and it resulted in it saying "The filename, directory name, or volume label syntax is incorrect"
I there some other command besides '>> Salesforce::Contact.first' that I should be using?
Thanks
>> (and similar things) represent the prompt that you should see already on the screen for you. It's essentially the console saying "Go ahead, type something"
Try to 'mentally' strip stuff like that off from the beginning, including spaces. This would mean that the 'command' you're looking to execute is really,
Salesforce::Contact.first
Hope this helps.
I have been eating my nails the whole weekend to figure out the right combination of modifications to the official refinerycms-calendar in order to make it work with RefineryCMS 2.1.1.
Here are my conclusions and efforts, hoping that someone will drive me to the right direction:
Adding just gem 'refinerycms-calendar', '~>2.0.0'
as suggested in the github page is not working out of the box. You need to correct the dependencies on the .gemspec file. There are many forks out there created only for this correction.
So, I forked the refinery/refinerycms-calendar project, corrected the dependencies and used my fork in the Gemfile.
Backend (BE) works fine: Created an event, went back to FrontEnd (FE), got a "This page is NOT live for viewing"
This frontend (FE) inconcistency is corrected to the BE > Pages > Venues page: /calendar/venues is not an existing route and needs to be corrected to /calendar/events. The seeds.rb needs to be corrected for a permanent solution.
Go back to FE, now the /calendar/events is blank! I only get the title of the Page as defined on the relative Pages page.
A look on the rails server log reveals that there is a :find_page error resulting form the fact that the refinerycms-events.css under the engine's public/stylesheets folder is neither picked up nor referenced correctly inside show.hrml.erb and index.html.erb files. I copied the refinerycms-events.css under vendor/stylesheets and changed the reference to refinerycms-events.css accordingly.
Refreshed FE but still there is a blank page both when getting /calendar/events and /calendar/events/#{event}
NOTE: If I "rake routes" I can see that the routes for the FE portion are repeated 3 times. I am not quite sure for this behavior, but when I substituted "Refinery::Core::Engine.routes.append do".gsub("append","draw"), I could only see them once.
I have tried many forks around and all of those seem to demonstrate the same behavior.
Can anybody please let me know:
a. If you finally managed to have this (official refinery release) engine fully functional in your projects and if yes which branch was used and with which exact Refinerycms and refinerycms-calendar version combination.
b. If used used a fork rather than the official refinerycms-calendar release, then which fork/branch is that.
I hope someone to have that nailed down.
Best regards,
Petros
Well, seems that changing :body_content_left and :body_content_right with :body and :side_body respectively inside the Engine's show and index views, solves the issue of the /calendar/events and /calendar/events/:event FE pages being blank.
I am still unsure why this is causing such an issue and it is kind of weird nobody to have reported it until now.
I'm using
link_to "Click Here", "http://www.cnn.com"
and its producing a link with the following href
"localhost:3000http://www.cnn.com"
For some reason, it's not recognizing the http:// as indicating an external URL, and treating it as a relative URL.
I tried going to the source of link_to and copied it into my application helper. I found that the .html_safe was doing the transformation, because when I pulled it out, it worked as expected.
I can't figure out which html_safe its using. When I copied in the source of HAML:Util.html_safe it also worked fine. Therefore, I assume the html_safe that link_to is using is resolving to something else, even though the view is a Haml file.
Based on what I see in the Haml method, it seems that html_safe calls html_safe! to transform the string when it thinks its unsafe.
I'm using the normal American English/Latin character set, so I don't see why it's not parsing the http:// correctly
I'm using Rails 2.3.5.
For now, I plan to hand-code the href into my view to avoid calling link_to for the external link, but if anyone can help me figure out what is going on, I'd greatly appreciate it. Thanks!
I'm unable to reproduce this behavior, but it sounds like a bug. Also please note that Rails 2.3.5 is quite old. I believe the current 2.3.x version is 2.3.12.
As a side note, the API docs you're referring to are for Rails 3.1.3. So you won't be able to obtain useful 2.3.5 debugging info from those docs. The easiest way to read the source that's actually in use in your app is to look in the gems folder on your development machine.
Anyhow, there's definitely nothing wrong with hand-coding the <a> tag like you're doing. In fact, it's slightly more efficient, as it avoids executing the Ruby code in link_to. So, it may actually be best just to keep doing what you're doing.
I had the same problem within an ERB file, my problem was solved when I used instead of an quoted an unquoted link and called html_safe afterwards. Maybe your problem will be safed too.
I'm trying various ways to implement pretty graphs in my app. I followed http://pullmonkey.com/projects/open_flash_chart2 steps in my app, but instead of creating test_it, I just added to my own controller. In my routes.rb, I have
resources :my_controller_name do
collection do
get 'graph_code'
end
end
also, since I don't think it could find the action my_controller_name/graph_code otherwise (I'm kind of confused as to why most tutorials leave the routes part out? Am I doing something wrong?). (I also used #graph.html_safe in my views for Rails 3)
Anyway when I go to /my_controller_name, I get the error in the flash box:
Open Flash Chart
JSON Parse Error [Syntax Error]
Error at character 0, line 1:
0: #<OpenFlashChart::OpenFlashChart:0x000001043c4b78
I don't know why this is happening. I tried creating a new app and following the guide, generating a controller named test_it. It worked (provided I corrected the routing). I can't think of how my controller is any different than test_it, except I initially generated it using a rails scaffold (so it has all the MVC parts), whereas I only generated the test_it controller. (I've also tried using/not using the json gem conflict fix, but it didn't make a difference--https://github.com/klochner/open_flash_chart/commit/00cf531387880af8c49ed5118737f0492b437f75) Thanks for any insight, I'm stumped as to why it's easy to implement on a new app but I can't add it to mine...
Thanks.
Nevermind, it seems to work if I use the old lib/base.rb instead of the json gem fix. Ah well.
Don't waste your time with Flash based charting libraries. Highcharts is definitely the way go to. It works in pretty much any browser, including those that don't support Flash. Much better performance on OS X than Flash will ever provide.