tag:blogger.com,1999:blog-21572324536139656202024-03-19T06:05:00.712-07:00DhavalOnRailsThe aim of this blog is to provide basic plugin implementation for RoR + I will guide you with the latest on going trend in RoR and help you implement certain services which are must for performance improvement helping you to create a better web app.
I will also give u step by step guidence of working on plugins that are required in most of the web 2.0 applications.Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.comBlogger25125tag:blogger.com,1999:blog-2157232453613965620.post-53084257644446927972009-04-25T22:09:00.000-07:002012-12-24T21:59:24.500-08:00No More Updating this blog<div dir="ltr" style="text-align: left;" trbidi="on">
Hey all<br />
<br />
I have shifted by blog on <a href="http://blog.dhavalparikh.co.in/">http://blog.dhavalparikh.co.in</a> So for latest information that you dont find here.. Please visit my new blog where you will get much more information.<br />
<br />
We have started a new Social Stock Market Portal<a href="http://stockarchitect.com/" target="_blank"> http://stockarchitect.com</a> to help investors take informed decision before buying and selling a stock. <br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuapNPcSnVhshyphenhyphen1z0p9Bp1qwu64gFhvzYZuUN_Hub9353T9n7DOsOlC5ull79SI_x_VEQz1JEm0exsby4J95kaUUinslAlEB2-F5Dc63KP9Jou-h-ip6BzlV1NaSeSZMUtGkLoOLl_neVI/s1600/sa.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuapNPcSnVhshyphenhyphen1z0p9Bp1qwu64gFhvzYZuUN_Hub9353T9n7DOsOlC5ull79SI_x_VEQz1JEm0exsby4J95kaUUinslAlEB2-F5Dc63KP9Jou-h-ip6BzlV1NaSeSZMUtGkLoOLl_neVI/s1600/sa.jpg" /></a></div>
<br />
<br />
Thanks<br />
<br />
Dhaval Parikh<br />
Software Engineer<br />
Ruby on Rails<br />
<a href="http://www.dhavalparikh.co.in/">http://www.dhavalparikh.co.in</a></div>
Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-29522978612244474252008-12-10T21:40:00.000-08:002008-12-10T21:44:39.469-08:00Spam filtering in rails using AkismetSPAM!!!! is a very big problem for all big applications. If you are having a site which allows users to comment on ur posts and so on then you might get affected by spamming.<br /><br />Akismet is something which is helping us to avoid spamming on our sites.<br /><br />There is a rails plugin available at http://github.com/jfrench/rakismet/tree/master<br /><br />You can download this and configure akismet in your rails app. more information is provided in read me file of the plugin.<br /><br />IF you want to see the actual implementation you can watch a screencast on<br /><br />http://railscasts.com/episodes/65-stopping-spam-with-akismet<br /><br />Hope this is some useful information for you.Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-33191186117302480342008-12-09T23:00:00.000-08:002008-12-09T23:03:08.581-08:00Counter Cache in rails 2.1Counter cache is really an important feature in rails 2.1 . This method is really helpful when u want to keep a count on something and avoid firing sql query every time which results in more processing times.<br /><br /><br />Here it goes<br /><br />To activate this feature, you need to take two simple steps. First, add the<br />option :counter_cache to the belongs_to declaration in the child table.<br /><br /><br />class LineItem < counter_cache =""> true<br />end<br /><br /><br />Second, in the definition of the parent table (products in this example) you<br />need to add an integer column whose name is the name of the child table with<br />_count appended.<br /><br /><br /><br />create_table :products, :force => true do |t|<br />t.column :title, :string<br />t.column :description, :text<br /># ...<br />t.column :line_items_count, :integer, :default => 0<br />end<br /><br />Thats it .. Counter cache is enabled now.Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-45265918790775305872008-11-20T07:57:00.000-08:002008-12-09T23:30:44.851-08:00Memcached with nginx on railsAs promised in my last article i m posting the way to configure memcached with nginx. Nothing much to do again<br /><br />Download memcached from http://www.danga.com/memcached/download.bml you might also require a memcache lib available on http://tangent.org/552/libmemcached.html install both of them and the memcached command will be available to you<br /><br />just type in this on the terminal<br /><br /><pre>memcached -p 11211<br /></pre>Thats it..now memcache is on. Just few more changes in the nginx.conf file and you r ready to zoom your rails app<br /><br />you just need to write this<br /><br /><br /><pre class="ruby">location /dynamic_request <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span><br /> <span style="color: rgb(0, 128, 0); font-style: italic;"># append an extenstion for proper MIME type detection</span><br /> <span style="color: rgb(153, 102, 204); font-weight: bold;">if</span> <span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>$args ~* <span style="color: rgb(204, 0, 102); font-weight: bold;">format</span>=json<span style="color: rgb(0, 102, 0); font-weight: bold;">)</span> <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span> rewrite ^/dynamic_request/?<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>.<span style="color: rgb(153, 0, 204);">*</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>$ /dynamic_request.<span style="color: rgb(153, 0, 204);">js</span>$<span style="color: rgb(0, 102, 102);">1</span> <span style="color: rgb(153, 102, 204); font-weight: bold;">break</span>; <span style="color: rgb(0, 102, 0); font-weight: bold;">}</span><br /> <span style="color: rgb(153, 102, 204); font-weight: bold;">if</span> <span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>$args ~* <span style="color: rgb(204, 0, 102); font-weight: bold;">format</span>=xml<span style="color: rgb(0, 102, 0); font-weight: bold;">)</span> <span style="color: rgb(0, 102, 0); font-weight: bold;">{</span> rewrite ^/dynamic_request/?<span style="color: rgb(0, 102, 0); font-weight: bold;">(</span>.<span style="color: rgb(153, 0, 204);">*</span><span style="color: rgb(0, 102, 0); font-weight: bold;">)</span>$ /dynamic_request.<span style="color: rgb(153, 0, 204);">xml</span>$<span style="color: rgb(0, 102, 102);">1</span> <span style="color: rgb(153, 102, 204); font-weight: bold;">break</span>; <span style="color: rgb(0, 102, 0); font-weight: bold;">}</span><br /><br /> memcached_pass <span style="color: rgb(0, 102, 102);">127.0</span><span style="color: rgb(0, 102, 102);">.0</span><span style="color: rgb(0, 102, 102);">.1</span>:<span style="color: rgb(0, 102, 102);">11211</span>;<br /><br /> error_page <span style="color: rgb(0, 102, 102);">404</span> = <span style="color: rgb(0, 102, 255); font-weight: bold;">@dynamic_request</span>;<br /><br />}<br /><br />Also you might require to set the uri so do this<br /><br /><span class="line"> <a href="http://wiki.codemongers.com/NginxHttpRewriteModule#set">set</a> <span class="ID">$memcached_key</span> <span class="ID">$uri</span>;</span><br /><span style="color: rgb(0, 102, 0); font-weight: bold;"></span></pre><br /><br />Ok thats done no restart nginx service and your memcache + mongrel cluster with gzip on will be running and ur rails app will be zoooooooooooooming<br /><br />NjoiDhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-20102057543435840292008-11-19T04:07:00.001-08:002008-11-19T19:54:56.057-08:00Nginx configuration, expiry headers and gzip component with rails - nginx.confJust configured nginx server with rails and here is the nginx.conf file. It also includes gzip component and header expiry which is advisable as per the yslow tool.<br /><br /># user and group to run as<br /><br /># number of nginx workers<br />worker_processes 4;<br /><br /># pid of nginx master process<br />#pid /var/run/nginx.pid;<br /><br /># Number of worker connections. 1024 is a good default<br />events {<br />worker_connections 1024;<br />}<br /><br /># start the http module where we config http access.<br />http {<br /># pull in mime-types. You can break out your config<br /># into as many include's as you want to make it cleaner<br />include mime.types;<br /><br /># set a default type for the rare situation that<br /># nothing matches from the mimie-type include<br />default_type application/octet-stream;<br /><br /># configure log format<br />log_format main '$remote_addr - $remote_user [$time_local] '<br /> '"$request" $status $body_bytes_sent "$http_referer" '<br /> '"$http_user_agent" "$http_x_forwarded_for"';<br /><br /># main access log<br />access_log /var/log/nginx_access.log main;<br /><br /># main error log<br />error_log /var/log/nginx_error.log debug;<br /><br /># no sendfile on OSX<br />sendfile on;<br /><br /># These are good default values.<br />tcp_nopush on;<br />tcp_nodelay off;<br /># output compression saves bandwidth<br />gzip on;<br />gzip_buffers 16 8k;<br />gzip_http_version 1.0;<br />gzip_comp_level 9;<br />gzip_proxied any;<br />gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/css;<br /><br /><br /># this is where you define your mongrel clusters.<br /># you need one of these blocks for each cluster<br /># and each one needs its own name to refer to it later.<br />upstream mongrel {<br /> server <a href="http://127.0.0.1:8000/" target="_blank">127.0.0.1:8000</a>;<br /> server <a href="http://127.0.0.1:8001/" target="_blank">127.0.0.1:8001</a>;<br /> server <a href="http://127.0.0.1:8002/" target="_blank">127.0.0.1:8002</a>;<br />}<br /><br /><br /># the server directive is nginx's virtual host directive.<br />server {<br /> # port to listen on. Can also be set to an IP:PORT<br /> listen 80;<br /><br /> # Set the max size for file uploads to 50Mb<br /> client_max_body_size 50M;<br /><br /> # sets the domain[s] that this vhost server requests for<br /><br /><br /> # doc root<br /> root /sites/sitename/public;<br /><br /> # vhost specific access log<br /> access_log /var/log/nginx.vhost.access.<div id=":g" class="ArwC7c ckChnd"><wbr>log main;<br /><br /> # this rewrites all the requests to the maintenance.html<br /> # page if it exists in the doc root. This is for capistrano's<br /> # disable web task<br /># if (-f $document_root/system/<wbr>maintenance.html) {<br /># rewrite ^(.*)$ /system/maintenance.html last;<br /># break;<br /># }<br /><br /> location / {<br /> # needed to forward user's IP address to rails<br /> proxy_set_header X-Real-IP $remote_addr;<br /><br /> # needed for HTTPS<br /> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br /> proxy_set_header Host $http_host;<br /> proxy_redirect false;<br /> proxy_max_temp_file_size 0;<br /><br /> if (-f $request_filename) {<br /> expires max;<br /> break;<br /> }<br /><br /><br /> # If the file exists as a static file serve it directly without<br /> # running all the other rewite tests on it<br /> if (-f $request_filename) {<br /> break;<br /> }<br /><br /> # check for index.html for directory index<br /> # if its there on the filesystem then rewite<br /> # the url to add /index.html to the end of it<br /> # and then break to send it to the next config rules.<br /> if (-f $request_filename/index.html) {<br /> rewrite (.*) $1/index.html break;<br /> }<br /><br /> # this is the meat of the rails page caching config<br /> # it adds .html to the end of the url and then checks<br /> # the filesystem for that file. If it exists, then we<br /> # rewite the url to have explicit .html on the end<br /> # and then send it on its way to the next config rule.<br /> # if there is no file on the fs then it sets all the<br /> # necessary headers and proxies to our upstream mongrels<br /> if (-f $request_filename.html) {<br /> rewrite (.*) $1.html break;<br /> }<br /><br /> if (!-f $request_filename) {<br /> proxy_pass <a href="http://mongrel/" target="_blank">http://mongrel</a>;<br /><br /> break;<br /> }<br /><br /> }<br /><br /> error_page 500 502 503 504 /500.html;<br /> location = /500.html {<br /> root /sites/sitename/public;<br /> }<br />}<br /><br />}<br /><br />In my next article i will also post how to configure memcache with rails and nginx<br /></div>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-74772168125690866272008-11-17T18:36:00.000-08:002008-11-29T21:52:19.352-08:00Load Balancing with pound and Mongrel ClusteringIn my previous post I have written about mongrel clustering..<br /><br />Now if you want to add the load balancing feature to it you may use pound. <em>Pound</em> is a software <em>HTTP</em> Load Balancer and Reverse Proxy.<br /><br />These are the steps how you can configure pound with mongrel cluster. First configure mongrel cluster as per the previous post.<br /><br />Then download and install pound from http://www.apsis.ch/pound/Pound-2.0.9.tgz<br /><br />Now the configuration step<br /><br />Pound.cfg needs to be configured which will reside in <strong>/etc/pound/pound.cfg<br /><br />also a symlink is required to be made<br /><br /></strong><pre><code>$ sudo ln -s /etc/pound/pound.cfg /usr/local/etc/pound.cfg<br /><br />A basic version of pound.cfg will look something like this<br /><br /></code><code>User "www-data"<br />Group "www-data"<br />LogLevel 2<br />Alive 30<br /><br />ListenHTTP<br /> Address 123.123.123.123<br /> Port 80<br />End<br /><br />Service<br /> HeadRequire "Host:.*www.dhavalparikh.co.in.*"<br /> BackEnd<br /> Address 127.0.0.1<br /> Port 8080 <br /> End<br /> Session<br /> Type BASIC<br /> TTL 300 <br /> End<br />End<br /><br />Service<br /> URL ".*.mov"<br /> BackEnd<br /> Address 69.12.146.109<br /> Port 8081 <br /> End<br /> Session<br /> Type BASIC<br /> TTL 300 <br /> End<br />End<br /><br />Service<br /> # Catch All<br /> BackEnd<br /> Address 127.0.0.1<br /> Port 9000 <br /> End <br /> BackEnd<br /> Address 127.0.0.1<br /> Port 9001<br /> End<br /> Session<br /> Type BASIC<br /> TTL 300<br /> End<br /><br /><br />Then start pound with the following command<br /><br /></code><code>$ sudo /etc/init.d/pound start</code><code><br /><br />finally you will have mongrel cluster setup done so start mongrel cluster<br /><br /></code><code>sudo mongrel_rails cluster::start<br /><br />Thats it you mongrel cluster with pound configuration is done..<br />njoi the power of load balancing<br /></code></pre><br /><br /><em></em><em></em>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-21497862041035378982008-11-08T19:43:00.000-08:002008-11-08T19:51:17.097-08:00Mongrel Clustering with Rails<span style="font-size:100%;">Hey every one wants to make their site run faster..and there are many ways like caching (page caching, fragment caching, method caching) so on. One other way is using mongrel cluster which will run multiple instance of mongrel on you server which will help to improve website speed to a huge extent.<br /><br />Let me tell you the steps for doing mongrel clustering .. its really easy..<br /><br />Step 1 : - Install mongrel cluster gem<br /><br />sudo gem install mongrel_cluster<br /><br />Step 2 : - configure cluster and run the config file which will reside in config/mongrel_cluster.yml<br /><span style="font-family: monospace;"><br /></span></span><pre><span style="font-size:100%;"><code>mongrel_rails cluster::configure -p 8000 -e production -a 127.0.0.1<br /><br />Well thats it now here you go<br /><br /></code><br />Start the cluster:<br /><code>mongrel_rails cluster::start</code><br /><br />Restart the cluster:<br /><code>mongrel_rails cluster::restart</code><br /><br />Stop the cluster:<br /><br /><code>mongrel_rails cluster::stop</code><br /></span></pre><span style="font-size:100%;"><br /></span><pre><span style="font-size:100%;"><code>Well just try these steps and if you are not able to configure it just post a<br />comment and i will get back to you.<br /><br />Enjoy better speed :)<br /></code></span></pre>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-88059696514686527152008-09-17T20:50:00.000-07:002008-09-17T20:55:29.359-07:00Page Screenshot in RailsHave you ever been through a situation where you need to embed a Flash object or some other element in a pdf file which cant be done directly? There is gr8 solution for it<br /><br />with the help or combination of RMagick + Image Magick + win32Screenshot gem you can take the screenshot of the desktop or webpage and generate an image from it and eventually embed it in your pdf file<br /><br />Here is the code for it<br /><br /><span class="Apple-style-span" style="font-family:Arial;"><pre>require 'win32screenshot'<br /></pre><pre>require 'RMagick' </pre><pre>def screenCapture </pre><pre> width, height, bitmap = Win32::Screenshot.desktop </pre><pre> img_lst = ImageList.new </pre><pre> img_lst.from_blob(bitmap) </pre><pre> img_lst.write('public/screen.png') </pre><pre> true </pre><pre>end<br /><br />If you are stuck any where just write to me or post a comment here<br />I would be pleased to solve your error<br /><br /></pre></span>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-56311264548941115432008-08-31T00:27:00.000-07:002008-08-31T00:31:50.337-07:00Flex On railsHi all<br /><br />With the increasing number of sites being made in RIA - Rich Internet Applications many people have adopted Rails + Flex for make a Rich Internet Application.<br /><br />There is a very gr8 plugin or code available on code.google.com known as ruby on rails ria sdk by adobe. Here is the url for it<br /><br /> http://code.google.com/p/rubyonrails-ria-sdk-by-adobe/<br /><br />The Ruby on Rails RIA SDK by Adobe provides developers with samples and code to help develop solutions with Ruby and Adobe technologies. The SDK includes open source code created by third parties as well as samples and demos that have been created by project members.<br /><br />You can download an initial .zip file containing all the files using the Download link on the right hand side, or you can check out the code via SVN by clicking on the 'Source' tab on the top of the page.<br /><br />This will help you to get things going and working with Rails + Adobe technology.<br /><br /><br />Hope this helps<br /><br />Thanks<br /><br />Dhaval Parikh<br />Software Engineer<br />Ruby on Rails<br /><a href="http://www.dhavalparikh.co.in">http://www.dhavalparikh.co.in</a>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-59415901517536458972008-08-20T08:27:00.000-07:002008-09-27T06:46:23.388-07:00Latest RoR pluginsHi all<br /><br />I am creating this post for all those who wants to get updated regarding whats demanding in RoR and which are the new plugins which will eventually make their coding easier and faster...<br /><br />So as and when i will come across such link or sites or plugins I will be updating so keep visiting this page...<br /><br />Also I might have implemented these plugins and would be tested..so if you have any problem in implementing them do write a mail to me.<br /><br /><br />1) Dynamic Tags with RoR :- Tagging for faster search<br /><br />http://agilewebdevelopment.com/plugins/dynamically_tags and http://blog.jasoncrystal.com/2008/08/17/rails-plugin-dynamically_tags/<br /><br />2) Open id integration with Rails :- A plugin that makes openid super simple.<br /><br />http://github.com/madnificent/openid_enabled/wikis<br /><br /><br />3) Google Sitemap :- A google sitemap plugin for rails websites. It generates dynamic sitemaps based on your models and named routes. It has a full mvc stack that you can configure.<br />http://agilewebdevelopment.com/plugins/sitemap<br />http://gethandcrafted.com/<br /><br />4) attachment_fu_app_engine : - Extension for AttachmentFu (<a href="http://github.com/technoweenie/attachment_fu">http://github.com/technoweenie/attachment_fu</a>) which uses the Google App Engine for storage and image resizing. Allows you to add or change thumbnail sizes without migrating previous data and removes the need to install ImageMagick.<br /><br />Here are few new additions which I found useful have a look @ them<br /><br />1) RQuote :- Gets realtime stock quotes from Yahoo Finance.<br /><br />http://github.com/johnyerhot/rquote/tree/master download and njoi very easy to implement<br /><br />2) Mobile_fu :- If Want to automatically detect mobile devices that access your Rails application? Mobile Fu allows you to do just that. People can access your site from a Palm, Blackberry, iPhone, Nokia, etc. and it will automatically adjust the format of the request from :html to :mobile.<br /><br />script/plugin install git://github.com/brendanlim/mobile-fu.git<br /><br />3) Act As nice url :- This acts_as extension provides the<br />capabilities for creating a nice url based on an attribute of the current object.<br />You can set / unset the object id in front of the URL and choose the object<br /> attribute to use to generate the URL.<br />more to go.. Even you can post good plugins which are new by commenting on this post<br /><br />Thanks<br /><br />Dhaval Parikh<br />Software Engineer<br />Ruby on Rails<br /><a href="http://www.dhavalparikh.co.in/">http://dhavalparikh.co.in</a>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-56150781563587655442008-07-04T21:31:00.000-07:002008-07-04T21:39:55.256-07:00Open SSL with Rails<pre>Well I was recently working with one application and<br />had to configure SSL with it..<br />Initially I faced few problems like I was getting the following Error<br /><br />no such file to load -- openssl then I searched a lot and<br />found the following solution<br /><br />IT will be helpful to all who face the same problem or who<br /> wants to configure Open SSL<br /><br />install openssl:<br /><br />./config --prefix=/usr/local --openssldir=/usr/local/ssl<br />make<br />make test<br />make install (as root)<br />./config shared --prefix=/usr/local --openssldir=/usr/local/ssl<br />make clean<br />make<br />make install (as root)<br />cd /usr/local/ssl/lib<br />cp * /usr/lib<br /><br />To avoid getting the following error later when you compile OpenSSH:<br /><br />configure: error: Your OpenSSL headers do<br />not match your library<br /><br />copy all the SSL include files everywhere:<br /><br />cd /home/tjnelson/openssl/openssl-*<br />cd include/openssl<br />cp * /usr/include<br />cp * /usr/local/ssl/include<br />cp * /usr/local/ssl/include/openssl<br /><br />and then add /usr/local/ssl/lib to /etc/ld.so.conf and type<br /><br />ldconfig<br /><br />Then i returned to ruby-*/ext/openssl and ran:<br /><br />ruby extconf.rb<br />make clean<br />make<br />make install<br /><br />This method works perfectly<br /><br />Dhaval Parikh<br />http://www.dhavalparikh.co.in<br /></pre>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-26462539142361679182008-07-01T04:38:00.000-07:002008-07-04T22:32:45.092-07:00Contact List importer in railsWell I have been hearing this question a lot..Every one wants to market about their site directly from their place..So for that these days people are integrating 3rd party services where they can import contact lists from various address books such as gmail, yahoo, aol and so on...So I integrated plaxo which rails inorder to get this functionality in my site..<br /><br />Here we go<br /><br />First of all load these js in views<br /><br /><br /><pre id="line43"><span class="attribute-value">http://www.plaxo.com/css/m/js/util.js</span><br /><span class="attribute-value">http://www.plaxo.com/css/m/js/basic.js</span><span class="end-tag"></span><br /><span class="attribute-value">http://www.plaxo.com/css/m/js/abc_launcher.js</span><span class="end-tag"></span></pre><br /><br />this will help u to open the plaxo page where u will be able to nter the login details of your desired mail account and then import all the email list<br /><br />This is the controller code which u need to write for calling the send mail option<br /><br />def sendemail<br />@emails = params[:recipients].split(',')<br />for email in @emails<br />@send = Emailer.deliver_allcontacts(email,"", "Just Test", "Dont Worry its just an testing email")<br />end<br />flash[:notice] = "Mails are successfully sent"<br />redirect_to :action => 'invite'<br />end<br /><br /><br />finally the model<br /><br />def allcontacts(to,from,subject,message)<br />@tomail = to<br />@from = from<br />@subject = subject<br />@body["message"] = message<br />end<br /><br />this will send mail to all the contacts in the list..<br /><br />Thats it..Now do marketing directly from ur website..<br /><br />Dhaval Parikh<br />Software Engineer<br />Ruby on Rails<br /><a href="http://www.dhavalparikh.co.in/">http://www.dhavalparikh.co.in</a>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-54012577678117475462008-06-14T21:35:00.001-07:002008-06-14T21:36:04.407-07:00Some Of RoR Resources<span style="text-decoration: underline;">Here are some of the RoR resources from where u can get all the details you want regarding RoR You may add your sites via comments<br /></span><ul><li><p><a target="_blank" href="http://www.ruby-lang.org/en/">Main Ruby Site</a> - Official Ruby site. Find a complete list of all documentation, tutorials, news etc.</p></li><li><p><a target="_blank" href="http://www.ruby-doc.org/">Ruby Documentation</a> - Ruby documentation site.</p></li><li><p><a target="_blank" href="http://rubyinstaller.rubyforge.org/">Ruby Installation</a> - One-Click Ruby Installer for Windows.</p></li><li><p><a target="_blank" href="http://rubyforge.org/">RubyForge</a> - Open source project repository.</p></li><li><p><a target="_blank" href="http://www.rubyonrails.org/">Ruby on Rails</a> - Official site for Ruby on Rails.</p></li><li><p><a target="_blank" href="http://docs.rubygems.org/">RubyGems</a> - Download link for RubyGem and other documentation.</p></li><li><p><a target="_blank" href="http://api.rubyonrails.org/">Rails APIs</a> - A comprehensive list of Rails APIs</p></li><li><p><a target="_blank" href="http://railsconf.com/">Rails Conf</a> - RailsConf, co-presented by Ruby Central, Inc. and O'Reilly Media, Inc., is the largest official conference dedicated to everything Rails.</p></li><li><p><a target="_blank" href="http://www.rubycentral.com/">Ruby Central</a> - Ruby Central, Inc., is a 501(c)(3) tax-exempt organization, dedicated to Ruby support and advocacy.</p></li><li><p><a target="_blank" href="http://www.mysql.com/">MySQL Homepage</a> - Here you can download the latest MySQL release, get the MySQL news update. The mailing list is also a great resources for anyone who want to build dynamic websites using MySQL.</p></li></ul>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-29566656837531219792008-06-04T21:36:00.000-07:002008-06-04T21:40:51.030-07:00Setting Up meta tags in RoR application For SEO<div class="body">
<br />Meta tags are one of the important aspect for any site. And RoR having the power for clean urls setting up proper meta tags will really do wonders for the site.
<br />
<br />So here is the method to setup the meta tags dynamically for all the pages
<br /><p>Here’s what I do (and it’s just one way of many) :</p> In my layout/application.rhtml <table class="CodeRay"><tbody><tr> <td class="line_numbers"><pre>1<tt>
<br /></tt>2<tt>
<br /></tt>3<tt> </tt></pre></td> <td class="code"><pre><title></title><%= <span class="iv">@meta_title</span> <span class="s"><span class="dl">%></span><span class="k"> My Site Name</span><span class="dl">></span></span><tt>
<br /></tt><meta name="<span" class="s"><span class="dl">"</span><span class="k">keywords</span><span class="dl">"</span> content=<span class="s"><span class="dl">"</span><span class="k"><%= @meta_keywords %></span><span class="dl">"</span></span> /><tt>
<br /></tt><meta name="<span" class="s"><span class="dl">"</span><span class="k">description</span><span class="dl">"</span> content=<span class="s"><span class="dl">"</span><span class="k"><%= @meta_description %></span><span class="dl">"</span></span> /></pre></td> </tr></tbody></table> <p>In my application controller:</p> <table class="CodeRay"><tbody><tr> <td class="line_numbers"><pre>1<tt>
<br /></tt>2<tt>
<br /></tt>3<tt>
<br /></tt>4<tt>
<br /></tt>5<tt>
<br /></tt>6<tt>
<br /></tt>7<tt>
<br /></tt>8<tt> </tt></pre></td> <td class="code"><pre> before_filter <span class="sy">:meta_defaults</span><tt>
<br /></tt> private<tt>
<br /></tt><tt>
<br /></tt> <span class="r">def</span> <span class="fu">meta_defaults</span><tt>
<br /></tt> <span class="iv">@meta_title</span> = <span class="s"><span class="dl">"</span><span class="k">Welcome to</span><span class="dl">"</span></span><tt>
<br /></tt> <span class="iv">@meta_keywords</span> = <span class="s"><span class="dl">"</span><span class="k">my keywords</span><span class="dl">"</span></span><tt>
<br /></tt> <span class="iv">@meta_description</span> = <span class="s"><span class="dl">"</span><span class="k">my meta description</span><span class="dl">"</span></span><tt>
<br /></tt> <span class="r">end</span></pre></td> </tr></tbody></table> and then in individual actions in my controllers I override the defaults <table class="CodeRay"><tbody><tr> <td class="line_numbers"><pre>1<tt>
<br /></tt>2<tt>
<br /></tt>3<tt>
<br /></tt>4<tt>
<br /></tt>5<tt> </tt></pre></td> <td class="code"><pre><span class="r">def</span> <span class="fu">view</span><tt>
<br /></tt> <span class="iv">@article</span> = <span class="co">Article</span>.find(params[<span class="sy">:id</span>])<tt>
<br /></tt> <span class="iv">@meta_title</span> = <span class="s"><span class="dl">"</span><span class="il"><span class="dl">#{</span><span class="iv">@article</span>.name<span class="dl">}</span></span><span class="k"> - </span><span class="dl">"</span></span><tt>
<br /></tt> <span class="iv">@meta_description</span> = <span class="iv">@article</span>.short_description<tt>
<br /></tt><span class="r">end</span></pre></td> </tr></tbody></table> <p>There are many other ways to do it..If there is a better way that you have pls share ur views below.</p>
<br /><p></p>
<br />
<br /></div>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-89974568940291070902008-05-31T21:14:00.001-07:002008-05-31T21:15:11.843-07:00Rails Migration<p>Rails Migration allows you to use Ruby to define changes to your database schema, making it possible to use a version control system to keep things synchronised with the actual code.</p> <p>This has many uses, including: </p> <ul><li><p>Teams of developers - if one person makes a schema change, the other developers just need to update, and run "rake migrate".</p></li><li><p>Production servers - run "rake migrate" when you roll out a new release to bring the database up to date as well.</p></li><li><p>Multiple machines - if you develop on both a desktop and a laptop, or in more than one location, migrations can help you keep them all synchronised.</p></li></ul> <h2>What can Rails Migration do?</h2> <ul><li><p>create_table(name, options)</p></li><li><p>drop_table(name)</p></li><li><p>rename_table(old_name, new_name)</p></li><li><p>add_column(table_name, column_name, type, options)</p></li><li><p>rename_column(table_name, column_name, new_column_name)</p></li><li><p>change_column(table_name, column_name, type, options)</p></li><li><p>remove_column(table_name, column_name)</p></li><li><p>add_index(table_name, column_name, index_type)</p></li><li><p>remove_index(table_name, column_name)</p></li></ul> <p><b>Migrations support all the basic data types:</b> string, text, integer, float, datetime, timestamp, time, date, binary and boolean:</p> <ul><li><p><b>string -</b> is for small data types such as a title.</p></li><li><p><b>text -</b> is for longer pieces of textual data, such as the description.</p></li><li><p><b>integer -</b> is for whole numbers.</p></li><li><p><b>float -</b> is for decimals.</p> </li><li><p><b>datetime and timestamp -</b> store the date and time into a column.</p></li><li><p><b>date and time -</b> store either the date only or time only.</p></li><li><p><b>binary -</b> is for storing data such as images, audio, or movies.</p></li><li><p><b>boolean -</b> is for storing true or false values.</p></li></ul> <p>Valid column options are:</p> <ul><li><p><strong>limit</strong> ( :limit => “50” )</p></li><li><p><strong>default</strong> (:default => “blah” )</p></li><li><p><strong>null</strong> (:null => false implies <span>NOT NULL</span>)</p></li></ul> <p><b>NOTE:</b> The activities done by Rails Migration can be done using any front end GUI or direct on SQL prompt but Rails Migration makes all those activities very easy.</p> <p>See the <a target="_blank" href="http://api.rubyonrails.org/classes/ActiveRecord/Migration.html">Rails API</a> for details on these.</p> <h2>Create the migrations:</h2> <p>Here is the generic syntax for creating a migration:</p> <table class="src" cellpadding="5"><tbody><tr><td><pre>C:\ruby\application> ruby script/generate migration table_name<br /></pre></td></tr></tbody></table> <p>This will create the file db/migrate/001_table_name.rb. A migration file contains basic Ruby syntax that describes the data structure of a database table.</p> <p><b>NOTE:</b> Before running migration generator, its recommended to clean existing migrations generated by model generators.</p> <p>We will create two migrations corresponding to our three tables <b><i>books and subjects</i></b>.</p> <table class="src" cellpadding="5"><tbody><tr><td><pre>C:\ruby> cd library<br />C:\ruby\library> ruby script/generate migration books<br />C:\ruby\library> ruby script/generate migration subjects<br /></pre></td></tr></tbody></table> <p>Notice that you are using lower case for book and subject and using the plural form while creating migrations. This is a Rails paradigm that you should follow each time you create a Migration.</p> <h2>Edit the code to tell it what to do:</h2> <p>Go into db/migrate subdirectory of your application and edit each file one by one using any simple text editor.</p> <p>Modify 001_books.rb as follows:</p> <p>The ID column will be created automatically, so don't do it here as well.</p> <table class="src" cellpadding="5"><tbody><tr><td><pre>class Books < ActiveRecord::Migration<br /> def self.up<br /> create_table :books do |t|<br /> t.column :title, :string, :limit => 32, :null => false<br /> t.column :price, :float<br /> t.column :subject_id, :integer<br /> t.column :description, :text<br /> t.column :created_at, :timestamp<br /> end<br /> end<br /><br /> def self.down<br /> drop_table :books<br /> end<br />end<br /></pre></td></tr></tbody></table> <p>The method <b>self.up</b> is used when migrating to a new version, <b>self.down</b> is used to roll back any changes if needed. At this moment abobe script will be used to create <b><i>books</i></b> table.</p> <p>Modify 002_subjects.rb as follows:</p> <table class="src" cellpadding="5"><tbody><tr><td><pre>class Subjects < ActiveRecord::Migration<br /> def self.up<br /> create_table :subjects do |t|<br /> t.column :name, :string<br /> end<br /> Subject.create :name => "Physics"<br /> Subject.create :name => "Mathematics"<br /> Subject.create :name => "Chemistry"<br /> Subject.create :name => "Psychology"<br /> Subject.create :name => "Geography"<br /> end<br /><br /> def self.down<br /> drop_table :subjects<br /> end<br />end<br /></pre></td></tr></tbody></table> <p>Above script will be used to create <b><i>subjects</i></b> table and will create five records in the subjects table.</p> <h2>Run the migration:</h2> <p>Now that you have created the migration files, you can execute it against the database.To do this, go to a command prompt and go to the library directory, in which the application is located, and then type <b>rake migrate</b>.</p> <table class="src" cellpadding="5"><tbody><tr><td><pre>C:\ruby\library> rake db:migrate<br /></pre></td></tr></tbody></table> <p>This will create a "schema_info" table if it doesn't exist which tracks the current version of the database - each new migration will be a new version, and any new migrations will be run until your database is at the current version.</p> <p><b>Rake</b> is a Ruby build program similar to the Unix make program that Rails takes advantage of to simplify the execution of complex tasks such as updating a database's structure etc.</p> <h2>Running migrations for production and test databases:</h2> <p>If you would like to specify what rails environment to use for the migration, use the RAILS_ENV shell variable.</p> <p>For example:</p> <table class="src" cellpadding="5"><tbody><tr><td><pre>C:\ruby\library> set RAILS_ENV=production<br />C:\ruby\library> rake db:migrate<br /></pre></td></tr></tbody></table><br /><table class="src" cellpadding="5"><tbody><tr><td><pre>C:\ruby\library> set RAILS_ENV=test<br />C:\ruby\library> rake db:migrate<br /></pre></td></tr></tbody></table><br /><table class="src" cellpadding="5"><tbody><tr><td><pre>C:\ruby\library> set RAILS_ENV=development<br />C:\ruby\library> rake db:migrate<br /></pre></td></tr></tbody></table> <p><b>NOTE:</b> On Unix, use "export RAILS_ENV=production" instead of set.</p><br />source : - tutorialspointDhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-22686004573511308752008-04-26T20:33:00.001-07:002008-04-26T20:33:23.194-07:00Ruby GemsA gem is a packaged Ruby application or library. It has a name and a version and have a specific task. Based on your requirement you may embed them into your application codes.<br /><br />For eg.<br />activerecord 0.8.4<br />BlueCloth 0.0.4<br />captcha 1.1.2<br />cardinal 0.0.4<br />progressbar 0.0.3<br />rake 0.4.0<br /><br />Gems are managed on your computer using the gem command. You can install, remove, and query gem packages using the gem command.<br /><br />Installing RubyGems:<br />RubyGems is the name of the project that developed the gem packaging system and the gem command. You can get RubyGems from the RubyForge repository http://rubyforge.org/frs/?group_id=126<br />then type<br />ruby setup.rb<br />It installs the required library files and the gem command. This command gives us the power to do many things.<br /><br />In a shortcut version at CLI we may use<br />q for query<br />r for remote<br />l for local<br />n for name<br />spec for specification<br /><br />Listing remotely installable gems<br />gem query –remote<br /><br />Searching remotely installable gems<br />gem query –remote –name-matches doom<br /># shortcut: gem q -R -n doom<br /><br />Installing a remote gem<br />gem install –remote progressbar<br />or<br />gem ins -r progressbar-0.0.3<br />or<br />gem ins -r progressbar –version ‘> 0.0.1′<br />RubyGems allows you to have multiple versions of a library installed and choose in your code which version you wish to use.<br /><br />Looking at an installed gem<br />gem specification progressbar<br /><br />Listing all installed gems<br />gem query –local<br /><br />remote or local<br />If you don’t specify either of these, then gem will (usually) try ’’both’’ a local and remote operation. For example:<br />gem ins rake # Attempt local installation; go remote if necessary<br />gem list -b ^C # List all local AND remote gems beginning with “C”<br /><br />Coding With RubyGems<br />require ‘rubygems’<br />require ‘progressbar’<br />and then subsequently<br />bar = ProgressBar.new(”Example progress”, 50)<br /><br />The first line of the program requires the progressbar library file. RubyGems will look for the progressbar.rb file in the standard library locations. If not found, it will look through its gem repository for a gem that contains progressbar.rb. If a gem is used, RubyGems attempts to use the latest installed version by default.<br /><br />Specifying Versions<br />gem install –remote rake –version “0.4.14″<br /><br />Updating RubyGems<br />gem update –system<br />or<br />gem install rubygems-update<br />update_rubygems<br /><br />Uninstalling a gem<br />gem uninstall progressbar<br /><br />Info extracted from : http://rubyforge.org/Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-85908155816924329832008-04-26T20:31:00.001-07:002008-04-26T20:31:32.500-07:00exception handling in ruby>begin expression executes its body and returns the value of the last evaluated expression.<br />>Any error in begin part will be caught by rescue depending upon parameters<br />>ensure is the one which must be exectued irrespective of exception occured or not<br />>An error message caught by an exception can be accessed using $!<br /><br />For Java Programmers [ begin => try ; rescue => catch; ensure => finally]<br /><br />begin<br /> p "I am doing well"<br /> p "so well .. and well"<br /> a = 8/0<br />rescue<br /> p "Something went wrong => " + $!<br />ensure<br /> p "Oh Somehow I could finish my work"<br />end<br /><br />O/P:<br /><br />“I am doing well”<br />“so well .. and well”<br />“Something went wrong => divided by 0″<br />“Oh Somehow I could finish my work”<br /><br />a = 8<br />b = 0<br />begin<br /> p "I am doing well"<br /> p "so well .. and well"<br /> if a==18<br /> p "I am happy with a as 8"<br /> elsif b == 0<br /> p "Lets say I dont want this"<br /> raise Exception<br /> else<br /> raise<br /> end<br /><br />rescue<br /> p "Exception 1 caught here " + $!<br />rescue Exception<br /> p "Exception 2 caught here " +$!<br />ensure<br /> p "Oh Somehow I could finish my work"<br />end<br /><br />O/P for [[ a = 8 and b = 0 ]]<br />“I am doing well”<br />“so well .. and well”<br />“Lets say I dont want this”<br />“Exception 2 caught here Exception”<br />“Oh Somehow I could finish my work”<br /><br />O/P for [[ a = 8 and b = 1 ]]<br />“I am doing well”<br />“so well .. and well”<br />“Exception 1 caught here “<br />“Oh Somehow I could finish my work”Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-29614257242657583982008-03-26T20:46:00.000-07:002008-03-26T20:47:54.261-07:00Validating Email Addresses with RubyAfter my post on how to send email thru action mailer I thought of writing how to validate that email address and thought it would be useful for all.<br /><br />Here it goes <br /><br />In any application in which a user enters an email address, there is the very real possibility that the user will make a typo and your application will end up with an invalid address. You can have them enter it twice, but this seems clunky. And you can, of course, send an email with an activation link, which provides the only true validation, but there’s no need to bother sending the email if you know the address is no good. Furthermore, once you’re past the page where the user enters their email address, you’ve missed your chance to tell them there’s something wrong and they should correct it.<br /><br />So you really should do what you can to validate the address when the user enters it. I recently made a simple addition to my applications that helps a lot: verify that the domain name is valid.<br /><br />It’s surprisingly easy to do—especially with a little help from Peter Cooper’s excellent Beginning Ruby, which has a very useful chapter on network programming. The following code is adapted from his examples:<br /><br />require 'resolv'<br />def validate_email_domain(email)<br /> domain = email.match(/\@(.+)/)[1]<br /> Resolv::DNS.open do |dns|<br /> @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)<br /> end<br /> @mx.size > 0 ? true : false<br />end<br /><br />This example makes use of the Ruby standard library “resolv”, so you need to require it first.<br /><br />The first step is to separate the domain name from the rest of the email address. The regular expression captures the part of the string that follows the @ symbol.<br /><br />Then the code creates a new DNS resolver object and queries the resolver for an MX (mail exchanger) resource at the specified domain. This returns an array, which will be empty if there is no MX record for the domain.<br /><br />(Note: In a previous version of this article, I used Resolv.getaddress to see if there is a DNS entry for the domain, instead of checking for an MX record. This approach works most of the time, but it rejects any domain for which there is no A record. If a domain is used only for email and not for a web server, there might not be an A record. Also, some domains have an A record only for www.domain.com, which will also fail the simple getaddress test.)<br /><br />You can use something like the following in the validate method within the appropriate model:<br /><br />unless email.blank?<br /> unless email =~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/<br /> errors.add(:email, "Your email address does not appear to be valid")<br /> else<br /> errors.add(:email, "Your email domain name appears to be incorrect") unless validate_email_domain(email)<br /> end<br />end<br /><br />I first check to make sure the email address is not blank, because that’s detected by a simple validates_presence_of :email statement that produces a different error message.<br /><br />Then I make sure that the email address is at least syntactically reasonable, with a rather ugly regular expression, before bothering to check the DNS.<br /><br />It should be noted that the regex I use here isn’t designed to cover all of the RFC2822 cases, nor with other RFC drafts dealing with non-ASCII addressing.<br /><br />An even better approach would be to use an observer to validate the address with an Ajax call before the user submits the form.<br /><br />It is possible to take this a step further by sending the SMTP server referenced in the MX record a “RCPT TO:” command. In theory, this would check that the user name is valid as well as the domain name. This takes additional time, however, and I’ve read that the response from mail servers is often not reliable. If anyone has tried this, I’d appreciate any feedback on how well it worked.Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-65843904620260953252008-03-06T17:31:00.000-08:002008-03-08T19:46:00.119-08:00ActionmailerAction Mailer is the Rails component that enables applications to send and receive e-mail. In this chapter we will see how to send an email using Rails. So lets start with creating a emails project using following command.
<br />
<br />C:\ruby\> rails emails
<br />
<br />This will create required framework to proceed. Now we will start with configuring Action Mailer.
<br />
<br />Action Mailer - Configuration
<br />
<br />Following are the steps you have to follow to complete your configruation before proceeding with actual work:
<br />
<br />Go into config folder of your emails project and open environment.rb file and add the following line at the bottom of this file.
<br />
<br />
<br />ActionMailer::Base.delivery_method = :smtp
<br />
<br />This tells ActionMailer that you want to user SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.
<br />
<br />Add the following lines of code to the bottom of your environment.rb as well.
<br />
<br />ActionMailer::Base.server_settings = {
<br />:address => "smtp.dhavalparikh.co.in",
<br />:port => 25,
<br />:domain => "dhavalparikh.co.in",
<br />:authentication => :login,
<br />:user_name => "username",
<br />:password => "password",
<br />}
<br />
<br />
<br />The values given in double quotes will be different for your SMTP server. You can take this information from your Inernet Service Provider if you already don't know. You don't need to change port number 25 and authentication type if you ar eusing standard SMTP server.
<br />
<br />Next step will be to create a mailer
<br />
<br />Generate a mailer:
<br />Use the following command to generate a mailer as follows:
<br />
<br />C:\ruby\> cd emails
<br />C:\ruby\emails> ruby script/generate mailer Emailer
<br />
<br />
<br />This will create a file emailer.rb in app\models directory. Check the content of this file is as follows:
<br />
<br />class Emailer > ActionMailer::Base
<br />end
<br />
<br />
<br />Let's create one method as follows.
<br />
<br />class Emailer > ActionMailer::Base
<br />def contact(recipient, subject, message, sent_at = Time.now)
<br />@subject = subject
<br />@recipients = recipient
<br />@from = 'no-reply@yourdomain.com'
<br />@sent_on = sent_at
<br />@body["title"] = 'This is title'
<br />@body["email"] = 'sender@yourdomain.com'
<br />@body["message"] = message
<br />@headers = {}
<br />end
<br />end
<br />
<br />
<br />The contact method has four parameters a recipient, subject, message and a sent_at, which defines when the e-mail is sent. The method also defines six standard parameters that are a part of every ActionMailer method:
<br />
<br />@subject defines the e-mail subject.
<br />
<br />@body is a Ruby hash that contains values with which you can populate the mail template. You created three key-value pairs: title, email, and message
<br />
<br />@recipients is a list of the people to whom the message is being sent.
<br />
<br />@from defines who the e-mail is from.
<br />
<br />@sent_on takes the sent_at parameter and sets the timestamp of the e-mail.
<br />
<br />@headers is another hash that enables you to modify the e-mail headers. For example, you can set the MIME type of the e-mail if you want to send either plain text or HTML e-mail.
<br />
<br />Now we will create a mailer template which is just text with standard Rails placeholders scattered throughout.
<br />
<br />Put following code in app/views/contact.rhtml file
<br />
<br />Hi!
<br />
<br />You are having one email message from with a tilte
<br />
<br />
<br />and following is the message:
<br />
<br />
<br />Thanks
<br />
<br />
<br />Next we will create a controller for this application as follows:
<br />
<br />C:\ruby\emails> ruby script/generate controller Emailer
<br />
<br />
<br />Now lets define a controller method in emailer_controller.rb which will call Model method to send actual email as follows:
<br />
<br />class EmailerController < email =" @params[" recipient =" email[" subject =" email[" message =" email[" text =""> 'Message sent successfully'
<br />end
<br />end
<br />
<br />
<br />To deliver e-mail using the mailer.s contact method, you have to add deliver_ to the beginningof the method name. You add a return if request.xhr? line so that you can escape to Rails Java Scripr (RJS) if the browser does not support JavaScript and then tell the method to render a text message.
<br />
<br />You are almost done except to prepare a screen from where you will get user information to send email. So lets define one screen method index in controller and corresponding view:
<br />
<br />Add following code in emailer_controller.rb file
<br />
<br />def index
<br />render :file => 'app\views\emailer\index.rhtml'
<br />end
<br />
<br />
<br />Now let's define our view in app\views\emails\index.rhtml
<br />
<br /><h1>Send Email</h1>
<br /><p>bracket <label for="email_subject"bracket Subjectbracket /labelbracket
<br />bracket %= text_field 'email', 'subject' %bracket bracket /pbracket
<br />bracket pbracket bracket label for="email_recipient"bracket Recipientbracket /labelbracket :
<br />bracket %= text_field 'email', 'recipient' %bracket bracket /pbracket
<br />bracket pbracket bracket label for="email_message"bracket Messagebracket /labelbracket
<br />
<br />bracket %= text_area 'email', 'message' %bracket bracket /pbracket
<br />
<br />
<br />Now test your application by using http://127.0.0.1:3000/Emailer/index. This displays following screen and by using this screen now you will be able to send your message to anybody.
<br />
<br />This will send your message and will display text message that "Message sent successfully"
<br />
<br />Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-28043399842472027952008-02-26T19:59:00.000-08:002008-10-06T19:35:45.650-07:00Rmagick installation on UbuntuRmagick installation on Ubuntu<br /><br />I have seen many times that people are facing a lot of problem in installing RMagick and Image Magick on ubuntu.......The same problem was faced by me and i got it solve by following the steps given below<br /><br /><br />Download RMagick and Imagemagick..<br /><br />put RMagick in the vendors folder where u want it to run from and Image Magick on Desktop<br /><br />Go to the Path where Image Magick is stored and follow the steps<br /><br />1) ./configure<br /><br />2) make<br /><br />3) make install<br /><br /><br />if you get an error while doing this task<br /><br />type the following command in terminal<br /><br />apt-get install build-essential (make sure that ruby dev is installed)<br /><br /><br />once you have done this follow the above 3 steps and things should start working<br /><br />So thats all about ImageMagick<br /><br />now come RMagick installation<br /><br />move the the RMagick installation path and follow the steps<br /><br />1) ./configure<br /><br />Thats it..now things should work..<br /><br />I dont think u will get any error. If you get any post ur errors as comment and get it solved..<br /><br /><h1><a href="http://b.lesseverything.com/2007/6/24/setting-up-imagemagick-rmagick-on-redhat-centos">Setting up ImageMagick & rmagick on Redhat</a></h1><br /><br /><div class="entrybody"> <ol><li>sudo yum install libjpeg-devel libpng-devel glib2-devel fontconfig-devel zlib-devel libwmf-devel freetype-devel libtiff-devel</li><li>wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.3.2-9.tar.gz</li><li>tar zxzvf ImageMagick-6.3.2-9.tar.gz</li><li>cd ImageMagick-6.3.2-9</li><li>./configure</li><li>make</li><li>sudo make install</li><li>sudo gem install rmagick</li></ol> </div>Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-50472825469883290712008-02-20T18:10:00.001-08:002008-03-08T19:47:27.149-08:00Radiant CMSRadiant CMS<br /><br />Its a powerful open source CMS (Content Management System) developed in ruby on rails. Radiant 0.6.4 has just been released! This version includes a powerful extension system so developers can tailor Radiant to their specific needs. Here i gave you some instructions to deploy it on your localhost.<br /><br />First install the gem by<br /><br />% gem install --include-dependencies radiant<br /><br />Then create a radiant project of your own by <br /><br />% radiant --database [mysql|postresql|sqlite3] path/to/project<br /><br />for eg: <br />% radiant --database mysql my_radiant_application<br /><br /><br />Then you have to configure your database by edit your database.yml file like follows<br /><br />development:<br />adapter: mysql<br />database: my_radiant_development<br />username: root<br />password: admin<br />host: localhost<br /><br /># Warning: The database defined as 'test' will be erased and<br /># re-generated from your development database when you run 'rake'.<br /># Do not set this db to the same as development or production.<br />test:<br />adapter: mysql<br />database: my_radiant_test<br />username: root<br />password:<br />host: localhost<br /><br />production:<br />adapter: mysql<br />database: my_radiant_production<br />username: root<br />password: admin<br />host: localhost<br /><br /><br /><br />you can use any of the database modes listed in database.yml. Then based on your database configuration <br />database schema should created by <br /><br />% rake [environment] db:bootstrap<br /><br />for eg: % rake production db:bootstrap if u r in production environment<br /><br />Here u goes, start your server<br /><br />% mongrel_rails start -e , where mongrel is your server (Mongrel server)<br /><br /><br />Type the http://localhost:3000/admin to login. The user name is password should be known to you because <br />while creating schema it asks for u the admin user name and password.<br />In the application you can't see any model, controller or view files but its working <br />fine this is how possible is all those files are written along with the radiant gem that <br />u should installed before starting project. you can see those files in your local ruby gems folder.<br /><br />Thats all , now you can go ahead with some other own radiant application.<br />if you want more explanation go and visit Radiant home pageDhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-79680247222703852112008-02-17T05:57:00.000-08:002008-03-08T19:47:56.692-08:00CaptchaWell with increase in spamming this facility of captcha has done the magic although people always find some or the other reason to crack a security but for the time being this can be implemented..<br /><br />Captchator is a very good service which can be combined easily with RoR and implement captcha<br /><br />Jst few lines of code does the magic for you<br /><br />View :-<br />in img src call the follwing source http://captchator.com/captcha/image/$yoursessionid<br /><br />Just like the one below<br /><br /><img src="http://captchator.com/captcha/image/$yoursessionid" /><br /><br />Write the above lines in views which will display a random captcha on the form or the page<br /><br />Then http://captchator.com/captcha/check_answer/$yoursessionid/$answer using this fetch the value which is entered by the user <br /><br />If the answer is correct, the result is "1", if not, it is "0".<br /><br />You can check the same in ur browser<br /><br />Try it in your Browser:<br /><br /> 1. Go to http://captchator.com/captcha/image/(anything you like) and read the text from the picture.<br /> 2. Go to http://captchator.com/captcha/check_answer/(anything you like)/(text from the picture). If you entered the text correctly, you will see "1".<br /><br /><br />Thats it..Captcha Ready for ur site..Aviod spamming in 10 mins no more security and coding required.Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-48214199919277618642008-02-17T05:50:00.000-08:002008-03-08T19:48:17.135-08:00File Column PluginThis is another plugin which i have implemented for File uploading. The main advantage of this is that we can integrate RMagick to it easily for generating thumbnails and giving other properties to the plugin.<br /><br />The main thing after downloading the plugin from http://www.kanthak.net/opensource/file_column/file-column-0.3.1.tar.gz<br />you just need to put 2-3 lines of code and get things going <br /><br /><span style="font-weight:bold;">on the page from where u want to upload a file just write 1 line of code <br /></span><br /> <%= image_tag url_for_file_column("entry", "image") %><br /><br /><span style="font-weight:bold;">Controller will look something like where versions part can be included only if you configure Rmagick else just remove the 2nd line and use it :-<br /></span><br /> class Entry < ActiveRecord::Base<br /> file_column :image, :magick => { <br /> :versions => { "thumb" => "50x50", "medium" => "640x480>" }<br /> }<br /> end<br /><br /><br /><span style="font-weight:bold;">Lastly Model (the most imp part) :-</span> <br /><br />class Entry < ActiveRecord::Base<br /> file_column :image, :magick => { :geometry => "640x480>" }<br /> end<br /><br />write this in the model of the page where u want to implement the plugin<br /><br />Thats it.. njoiDhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-80823304588338928532008-02-17T05:44:00.000-08:002008-03-08T19:48:41.754-08:00Act As Threaded (Forums)Hi all looking out for making a forum for your site..<br /><br />this is one of the methods which i have implemented on www.pleasecoumtnein.org <br /><br />Act_As_threaded which is a tree structure forum where performance is a concern. The nested_set model is insert/update heavy but the whole tree can be retrieved in order from the database with a single query.<br /><br />It can be downloaded from http://i.nfectio.us/plugins/acts_as_threaded.zip <br /><br />More in depth execution and implementation will be shown here later on.Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0tag:blogger.com,1999:blog-2157232453613965620.post-409950242769617562008-02-14T18:28:00.000-08:002008-03-08T19:49:03.315-08:00Acts as AuthenticatedActs as Authenticated<br />Acts As Authenticated is a simple authentication generator plugin for Ruby on Rails. It is available in subversion at: <br /><br />http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated<br /><br />Use script/plugin to install it:<br /><br />Try This<br /><br />script/plugin source http://svn.techno-weenie.net/projects/plugins<br />script/plugin install acts_as_authenticated<br /><br />Or One-Line It<br /><br />script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated<br /><br />Then…<br /><br />script/generate authenticated user accountrake db:migrateStart your server and navigate to the account page:<br /><br />http://localhost:3000/account/indexThe whole idea behind the plugin is that you generate the code once and add in your application specific authentication actions. This makes no attempt to decide how your application’s authorizing works.Dhaval Parikhhttp://www.blogger.com/profile/12432856200963982323noreply@blogger.com0