I already wrote a blog on how to use Google maps in rails. Earlier blog is supported in rails 2.3.x version.
To supoort rails 3 application , certain changes are required in plugin.
Here I will show you what are those changes required.
Download YM4R plugin :
rails plugin install https://github.com/rorcraft/ym4r_gm
1. Add following method in class Varible under gm_plugin/mapping.rb
def to_str
@variable + “;”
end
2. Use raw method for each google maps methods to avoid html contents.
<%= raw GMap.header %>
<%= raw @map.to_html %>
<%= raw @map.div(:width => 600, :height => 400) %>
4. Add Ym4r js in your layouts
<%=javascript_include_tag :defaults,"ym4r-gm"%>
5. Commented line no: 35 in ym4r/lib/gm_plugin/map.rb
# a << "<script src=\"/public/javascripts/ym4r-gm.js\" type=\"text/javascript\"></script>\n" unless options[:without_js]
I hope this blog helps you. Let me know if you still facing any problem.
Here I will show you how to send email through ruby script.
Require NET/SMPT library in ruby script
require 'net/smtp'
Config SMTP authentication
def send_email(to,opts={})
opts[:server] ||= 'SERVER IP'
opts[:port] ||= PORT_NUMBER
opts[:domain] ||= "DOMAIN IP"
opts[:user_name] ||="USERNAME"
opts[:password] ||= "PASSWORD"
opts[:authentication] ||="plain"
opts[:from] ||= 'example@domain.com'
opts[:from_alias] ||= 'FROM NAME'
opts[:subject] ||= "SUBJECT SAMPLE"
opts[:body] ||= "MESSAGE BODY"
msg = <<END_OF_MESSAGE
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <#{to}>
Subject: #{opts[:subject]}
Content-type: text/html
#{opts[:body]}
END_OF_MESSAGE
Net::SMTP.start(opts[:server],opts[:port], opts[:domain],opts[:user_name], opts[:password],opts[:authentication]) do |smtp|
smtp.send_message msg, opts[:from], to
end
end
Now send email by passing arguments.
send_email "EMAIL ADDRESS", :body => "MESSAGE"
I hope this will helps you to send email through script.
If you get following error while extecuting ruby script/console
/usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require’: no such file to load — readline (LoadError)
from /usr/local/lib/ruby/1.8/irb/completion.rb:10
from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `require’
from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `load_modules’
from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `each’
from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `load_modules’
from /usr/local/lib/ruby/1.8/irb/init.rb:21:in `setup’
from /usr/local/lib/ruby/1.8/irb.rb:54:in `start’
from /usr/local/bin/irb:13
To solve this issue , you need to install some libraries.
sudo apt-get install libncurses5-dev
sudo apt-get install libreadline5-dev
Then goto ruby source folder and ext/readline folder
cd <RUBY SOURCE FOLDER>/ext/readline
ruby extconf.rb
make
sudo make install
This will solved your readline error. If you still facing any problem let me know.
Recently I upgrade my rails version from 2.3.2 to 2.3.4 and ruby version from 1.8 to 1.9 .
By changing version of ruby, I was facing problem in auto complete functionality.
To solve the issue , I applied below patch in lib/autocomeplete_macro_helper.rb file
def auto_complete_result(entries, field, phrase = nil)
return unless entries
items = entries.map { |entry| content_tag("li", phrase ? highlight(entry[field], phrase) : h(entry[field])) }
content_tag("ul", items.uniq.join)
end
I changed content_tag (“ul”, items.uniq) to content_tag(“ul”,items.uniq.join)