Graticule and Rails: REXML::ParseException: missing attribute quote - ruby-on-rails

I use graticule 1.0.0.pre2. When I try to locate some addresses that Google doesn't recognize, graticule raises an exception:
LibXML::XML::Error in Cms/storesController#update
Fatal error: Extra content at the end of the document at :1.
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/happymapper-0.3.2/lib/happymapper.rb:84:in `parse'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/happymapper-0.3.2/lib/happymapper.rb:84:in `parse'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/graticule-1.0.0.pre2/lib/graticule/geocoder/google.rb:82:in `prepare_response'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/graticule-1.0.0.pre2/lib/graticule/geocoder/base.rb:83:in `get'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/graticule-1.0.0.pre2/lib/graticule/geocoder/google.rb:36:in `locate'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/acts_as_geocodable-1.0.4/lib/acts_as_geocodable/geocode.rb:31:in `create_from_location'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/acts_as_geocodable-1.0.4/lib/acts_as_geocodable/geocode.rb:27:in `find_or_create_by_location'
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/acts_as_geocodable-1.0.4/lib/acts_as_geocodable.rb:262:in `attach_geocode'
...
...
I'm using the Google service. This is the response that generates the exception:
"<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/><title>Sorry...</title><style> body { font-family: verdana, arial, sans-serif; background-color: #fff; color: #000; }</style></head><body><div><table><tr><td><b><font face=times color=#0039b6 size=10>G</font><font face=times color=#c41200 size=10>o</font><font face=times color=#f3c518 size=10>o</font><font face=times color=#0039b6 size=10>g</font><font face=times color=#30a72f size=10>l</font><font face=times color=#c41200 size=10>e</font></b></td><td style=\"text-align: left; vertical-align: bottom; padding-bottom: 15px; width: 50%\"><div style=\"border-bottom: 1px solid #dfdfdf;\">Sorry...</div></td></tr></table></div><div style=\"margin-left: 4em;\"><h1>We're sorry...</h1><p>... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.</p></div><div style=\"margin-left: 4em;\">See Google Help for more information.<br/><br/></div><div style=\"text-align: center; border-top: 1px solid #dfdfdf;\">© 2009 Google - Google Home</div></body></html>"
With other addresses it works! How can I prevent that exception?

I received this same error. Using the Pry Debugger I placed a binding.pry under the Parse declaration in happy mapper. For you that would be
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/happymapper-0.3.2/lib/happymapper.rb:84:in `parse'
Restarted pry and ran
location = geocoder.locate("61 East 9th Street, Holland, MI")
The debugger stopped right after
def parse(xml, options = {})
I did a dump of the xml variable to receive an HTML dump from Google that included the message
<h1>We're sorry...</h1>
<p>... but your computer or network may be sending automated queries.
To protect our users, we can't process your request right now.</p>
See <a href="https://support.google.com/websearch/answer/86640">
Google Help
</a> for more information.
Haven't resolved yet but that's the issue.

Related

My Website Does Not Seem to Want to Print Anything

I have developed a website and am in the process of converting most of the tables over to DataTables. In testing out one of the DataTable features the Print button, I discovered that nothing would print except the Title of the web page. At first I thought it was an issue with DataTables, but after playing around I've discovered that none of my pages seem to want to print. I'm testing with Chrome because it has the Print Preview, but I can right-click on any page in my site and select Print... and I get the same behavior -- only the Title of the web page displays. Has anybody experienced anything like this before? Here's a link to my site:
JCPS DMC
Even on the home page, try right clicking and select Print and you'll see what I mean. Please tell me this is some super-easy that I just don't know about -- some setting that I've overlooked. I will be happy to provide any support information you need, but I don't even know what that would be... :(
Well this is embarrassing...apparently at some point I included a css script in my Master page (the site is developed using asp.net). In the css I had this little gem which was blocking anything from being printed:
#media print {
body
{
visibility: hidden;
border-top: hidden;
width: 50%;
}
.noPrint
{
display: none !important;
}
ol
{
display: none;
}
.printSection, .printSection *
{
visibility: visible;
margin: 1px;
padding: 1px;
}
.printSection
{
position: relative;
left: 0;
top: 0;
}
}
Not even sure why I put that in there, but I removed it and everything is working peachy now...

Display background image in Neo4j browser

Some nodes in my graph database have a property which contain a URL to an image. I wanted to use Neo4j browser's style sheet functionality to display that image as the background image of a node.
My .grass file looks like this:
node {
diameter: 40px;
color: #DFE1E3;
border-color: #D4D6D7;
border-width: 2px;
text-color-internal: #000000;
caption: '{name}';
font-size: 10px;
background-color: #00aaee;
}
node.Actor {
color: #AD62CE;
border-color: #9453B1;
text-color-internal: #FFFFFF;
background-image: url('{image}');
}
After I uploaded the file, the line background-image: url('{image}'); gets converted to background-image: url({image}); (missing apostrophes). No image is shown in the browser.
What am I doing wrong?
You're not doing anything wrong.
The feature is not supported in the Neo4j browser. Other visualization solutions do exist. Unfortunately the ones that use this feature out of the box are not open source and may require a commercial license.
Of these solutions are:
http://linkurio.us/
https://www.tomsawyer.com/products/visualization/index.php
http://www.keylines.com/
As #Kenny Bastani said most of the libraries that implement this feature have a commercial license.
For a full list of the supported ones have a look to the official Neo4J visualize page.

How to strip HTML tags including escaped image tags without ' and stuff?

I need to strip all the html elements from my content. Example of the content :
"<p><img alt=\"\" src=\"/ckeditor_assets/pictures/1/content_twitter-sink.jpg\" style=\"width: 570px; height: 399px;\" /></p>\r\n\r\n<h3 style=\"font-size: 1.38462em; margin: 1em 0px 0px; font-weight: 600; line-height: 1.2; font-family: freight-sans-pro, sans-serif; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility; color: rgb(46, 46, 46);\">Soraya Calavassy, communications manager at the Award in Australia, shares her organisation's experience piloting our new global visual identity.</h3>\r\n\r\n<p style=\"margin: 0.5em 0px 0px; text-rendering: optimizelegibility; font-size: 1.30769em; line-height: 1.3; color: rgb(78, 78, 78); font-family: freight-sans-pro, sans-serif;\">"While Australia has a very strong brand locally, there are some great benefits for incorporating"
When displaying the post i use raw which does give me the output I need. But I need to generate an excerpt. For that, I need to strip all the HTML tags and even remove the images. But when I use sanitize it won't remove the images. If I use strip_tags , it will remove the images but it will add ' for apostrophe, for space, etc. So, how to get a clean excerpt without images and without stuff?
try strip_tags(text).html_safe
Doesn't work with rails 4.1
Only way by combing strip_tags with the gsub function (link below)
Ruby gsub multiple characters in string
So in helper, I'd do:
def format_text(string)
strip_tags(string).gsub(" ", "").gsub("'", "'")
end
I meet problem with such code
strip_tags("<p>a</p>\r\n") # => a
I use
sanitize("<p>a</p>", tags: [ ]) # => a\r\n
raw(strip_tags(text).html_safe) is actually what you want

Custom values for some of the bootstrap-sass (v2.0.3) variables not working

I am trying to override some of the default variables provided by bootstrap, particularly some default color and font settings, but only a few them seem to be taking effect. Here's the top part of my custom.css.scss:
$myOrange:#f89406;
$myBlueDark: #304269;
$myBlue: #91BED4;
$myBlueLight: #D9E8F5;
$myWhite: #eee;
$myGrayBlue: #43464C;
/* colors */
$linkColor: $myBlueDark;
$navbarBackground: $myBlueDark;
$navbarBackgroundHighlight: lighten($navbarBackground, 10);
$navbarLinkColor: darken($myOrange, 10);
$navbarLinkColorHover: $myOrange;
$bodyBackground: #000;
$dropdownBackground: $myBlueDark;
$dropdownLinkColor: $myOrange;
$hrBorder: $myBlue;
$heroUnitBackground: lighten($myOrange, 20);
$dropdownLinkColorHover: $myOrange;
/* typography */
$sansFontFamily: 'PT Sans Narrow', 'Lucida Grande', serif;
$baseFontSize: 16px;
#import 'bootstrap';
// ... rest of the css ....
Here I have specified values for a few bootstrap variables and expect the font to be be the specified one and the link colors to be the values I've set them to.
However, I've noticed that only a few of these values work. E.g. the font on my page still stays at bootstrap default (Helvetica Neue) but the navigation bar colors change to the correct values.
I've searched around on the internet but none of the solutions I found worked. There was an issue logged which resembles this problem, but it has since been closed: https://github.com/thomas-mcdonald/bootstrap-sass/issues/102
I would go ahead and comment on that thread, but I just wanted to make sure that I am not missing something.
Another thing to notice here, when I explicitly do this later in my custom.css.scss:
#mixin default_font {
font-family: "PT Sans Narrow", "Lucida Grande", sans-serif;
font-weight: 400;
}
body {
padding-top: 60px;
background-color: #D9E8F5;
#include default_font;
}
The fonts show up fine. I am specifying background-color here because of the same problem.
I am using bootstrap-sass v2.0.3. Is there something I am doing wrong or missing?
Thanks.
While I was working on a demo app to reproduce my problem: https://github.com/verma/bootstrap-sass-tests I restarted the rails development server.
This seems to have fixed the issue. I am not really certain if this is a permanent fix, so I will wait before I mark this question as answered.
Removing the navbar-inverse style, from the class attribute in the header element, may fix the problem.
Use for example:
<header class="navbar navbar-fixed-top">
Hmm, I've had luck using this for fonts and link colors:
$baseFontSize: 17px;
$baseFontFamily: 'Crete Round', 'Helvetica Neue', Helvetica, Arial, sans-serif !default;
$baseLineHeight: 20px;
$altFontFamily: 'Open Sans Condensed', Georgia, "Times New Roman", Times, serif !default;
$headingsFontFamily: 'Alfa Slab One'; // empty to use BS default, #baseFontFamily
$headingsFontWeight: normal; // instead of browser default, bold
$headingsColor: $blueDark;
$linkColor: $blueDark;
The variables that you can use can be found in the _varibles.scss file.
What does your application.css.scss file look like? I ran into a similar problem and found that I had another stylesheet overriding my base font, which I didn't want. Make sure you don't have other files causing overrides (such as scaffolds.css) and make sure you do not have the require_tree option enabled.
I appended !important to the font-family for body and that fixed my issues.
Context:
I had a similar issue for my Rails 5 app where my custom fonts (.otf) was not applied. In the developer console, I see the body font applied as "Helvetica Neue" what I think is coming from bootstrap-sass.
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif
...
when I unchecked the font-family: "Helvetica Neue", I see my fonts as expected so I know the asset pipeline for my custom fonts was working correctly.
prepending !important seemed to have fixed my issue.
body {
font-family: 'Din-Light', 'Helvetica', 'Arial', 'sans-serif' !important;
}

QR Code Generator in Rails [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am looking for help to implement a QR Code generator on my site. The site is built in Ruby on Rails. I have tried to use rqrcode but could not seem to get it to work. I would like to use the google chart API.
OVERVIEW:
A simple QR code generator. In the view, a user can pass in a string, the string is then stored, and then sent to the QR code generator script, at this point the resulting QR Code image should be displayed back to the user.
Just released a gem that makes this very easy if you're using rails 3.
Follow the installation documentation at:
https://github.com/samvincent/rqrcode-rails3
See: http://code.google.com/apis/chart/infographics/docs/qr_codes.html.
QR codes are a popular type of two-dimensional barcode. They are also known as hardlinks or physical world hyperlinks. QR Codes store up to 4,296 alphanumeric characters of arbitrary text. This text can be anything, for example URL, contact information, a telephone number, even a poem! QR codes can be read by an optical device with the appropriate software. Such devices range from dedicated QR code readers to mobile phones...
I've both used google and the gem.
define #url in controller. Use google API.
<img src=<%="https://chart.googleapis.com/chart?chs=545x545&cht=qr&chl=#{#url}&choe=UTF-8"%> alt="QR code">
If for some reason you want to have a gem do it on your server the following is good.
gem 'rqrcode'
#qr = RQRCode::QRCode.new( #url, :size => 7, :level => :h )
## Your VIEW
<div id="qr">
<style type="text/css">
#qr table {
border-width: 0;
border-style: none;
border-color: #0000ff;
border-collapse: collapse;
}
#qr td {
border-left: solid 10px #000;
padding: 0;
margin: 0;
width: 0px;
height: 10px;
}
#qr td.black { border-color: #000; }
#qr td.white { border-color: #fff; }
</style>
<%= raw #qr.as_html %>
</div>

Resources