Now we have to create a scaffold. Do a following commands.
$ rails g nifty:scaffold Post title:string
$ rails g nifty:layout
It asks a Permission to Overwrite the layout file. just press “y”. It shoes like,
Overwrite /home/suresh/deal_projects/paperclip-test/app/views/layouts/application.html.erb? (enter “h” for help) [Ynaqdh]
Again migrate with db.
$ rake db:migrate
$ rm public/index.html
Then, Add the following line in your /config/routes.rb , root :to => “posts#index”
Then, create a model called “Asset”
$ rails g model Asset asset_file_name:string asset_content_type:string asset_file_size:integer asset_upload_at:datetime post_id:integer
$ rake db:migrate
Now in model folder, there is a file called “asset.rb”. Add the following lines into this file.
At 1991, Linus Torvalds, released his Kernel as open source. After that, the Linux Revolution happened.
To celebrate the 20 years of Linux, The Linux Foundation, is doing various activities.
Explore it here. http://www.linuxfoundation.org/20th
It released an animation video.
My Brother T.Shrinivasan wanted to translate the video in tamil. So he asked his friend to transcribe the audio as English text. He then also asked me to convert the English text into Tamil text.
class Location < ActiveRecord::Base
acts_as_gmappable
def gmaps4rails_address
address
end
def gmaps4rails_infowindow
"<h4>#{name}</h4>" << "<h4>#{address}</h4>"
end
end
add the line in controller /app/controllers/locations_controller.rb
def index
@locations = Location.all
@json = Location.all.to_gmaps4rails
..........
In your view app/views/locations/index.html.erb to add a last line as
<%= gmaps4rails(@json) %>
then start the server(http://localhost:3000/locations) to put the name and address, longitude and latitude as set automatically, then will be show the markers as corresponding address and click the marker icon.it will shows infowindow as name and address
That’s it!! If you have any questions please feel free to contact me. I will be happy to help where I can. 🙂
My need was send one time password via e-mail/sms ,who registered with their E-mail/mobile no.
Lets see “How to send SMS using Rails3 application and smsAPI”
At first we need a smsapi to send SMS via Rails3 application. There is a site, which provides FREE API to send SMS via programming. So, here we need to register with your Domain and mail-id. They also provide codes for various languages 🙂
Since last week i had worked with Send SMS via rails application. After long search, i found a site called “freesmsapi.com” which provides API and sends SMS. This site is very much helpful in sending automated SMS.
They also provide codes for different languages like “Python, Ruby, PHP, Perl, Java, C, C#, VB.NET”
When i compared the same code for different languages, I was surprised (shocked 😛 )to see that PYTHON and RUBY has the minimal and very efficient code. 🙂
use strict;
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $url='http://s1.freesmsapi.com/messages/send?skey=89600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER';
my $request = new HTTP::Request('GET', $url);
my $response = $ua->request($request);
my $content = $response->content();
print $content;
JAVA:
import java.net.*;
import java.io.*;
public class JavaGetUrl {
public static void main(String[] args) throws Exception {
URL myurl = new URL("http://s1.freesmsapi.com/messages/send?skey=89600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER");
BufferedReader in = new BufferedReader(
new InputStreamReader(
myurl.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
C:
#include <curl/curl.h>
void main() {
long http_code = 0;
CURL *curl;
CURLcode res;
//Initializing the CURL module
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER");
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if(http_code == 200) {
puts("Received 200 status code");
} else {
puts("Did not received 200 status code");
}
}
} else {
puts("Could not initialize curl");
}
}
Imports System.IO
Imports System.Net
Dim connectionString As String = "http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER"
Try
Dim SourceStream As System.IO.Stream
Dim myRequest As System.Net.HttpWebRequest = WebRequest.Create(connectionString)
myRequest.Credentials = CredentialCache.DefaultCredentials
Dim webResponse As WebResponse = myRequest.GetResponse
SourceStream = webResponse.GetResponseStream()
Dim reader As StreamReader = New StreamReader(webResponse.GetResponseStream())
Dim str As String = reader.ReadLine()
MessageBox.Show(str)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.
Lets see how to setup the actionmailer with Gmail SMTP.
First we have to create a rails application using
$ rails new action_mailer
Next we’ll generate a scaffold for a User model with name and email attributes to act as a simple user-registration page.
$ rails genetate scaffold user name:string email:string
Now we have to migrate with DB.
$ rake db:migrate
The generated scaffolding code includes a page for creating users. We want to create a new user and then send them a confirmation email when the form on this page is submitted.
The first thing we’ll do is create a new initializer file called setup_mail.rb and put some configuration options in it. ActionMailer will use sendmail if it’s set up on your machine but we can instead specify SMTP settings in the initializer.
You’ll probably want to use a different approach in a production application but this is a good enough approach while our application is in development. Obviously you’ll want to change the domain, user_name and password options to suit your own Gmail account.
Now that we’ve completed the configuration we can generate a new mailer with the following code:
$ rails generate mailer user_mailer
$ cd /app/mailer
$ gedit user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "thasuresh@gmail.com"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Registered")
end
end
Now we have to create a file called registration_confirmation.text.erb under app/views/user_mailer.
Now if you want add any attachments in the mail add this line into /app/mailer/user_mailer.rb
def registration_confirmation(user)
@user = user
attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
end
Here my need is send a numeric password, when a user subscribe with his mail id. The password will send by actionmailer. So i added the a single ruby command into
Hi <%= @user.name %>,
This is the one time password, You can login into our site using the password given below
Password: <%=rand(999999)%>
Thank You For Registering!