tag:blogger.com,1999:blog-15620520597060137732024-03-14T02:14:12.504-07:00Vikas Nandal@Rails + Web2.0 => :suwaadUnknownnoreply@blogger.comBlogger11125tag:blogger.com,1999:blog-1562052059706013773.post-48968657850535720552009-04-11T02:20:00.000-07:002009-06-11T02:33:31.742-07:00Image Rotation with Jquery PluginIt is a great plugin for rotation of images with the help of Jquery.<br /><br />This plugin is a copy of mooTools implementation made by Cédric for this library, check it out at <a href="http://www.piksite.com/mRotate/">http://www.piksite.com/mRotate/</a> (IT might be outdated!)<br /><br /><strong>Download:</strong><br /><br /><a href="http://wilq32.googlepages.com/jQueryRotate.js">jQueryRotate.js</a><br /><br /><strong>Description:</strong><br /><p><br />This is an final product of a Wilq32.PhotoEffect Snippet. Actually you can use this simple and tiny script to get effect of rotated images directly from client side (for ex. user generated content), and animate them using own functions.<br /></p><br /><strong>Usage:</strong><br /><p>jQuery(imgElement).rotate(angleValue)<br /></p><p>jQuery(imgElement).rotate(parameters)</p><p>jQuery(imgElement).rotateAnimation(parameters)<br /></p><p>jQuery(imgElement).rotateAnimation(parameters)<br /></p><strong><br />Returns:</strong><br /><br /><strong>jQueryRotateElement - !!! NOTICE !!! function return rotateElement instance to help connect events with actually created 'rotation' element.<br /></strong><br /><br /><strong>Parameters:</strong><br /><ul><br /> <li> ({angle:angleValue,<br /></li><br /><br /> <li> [animateAngle:animateAngleValue],<br /></li><br /><br /> <li>[maxAngle:maxAngleValue],<br /></li><br /><br /> <li> [minAngle:minAngleValue],<br /></li><br /><br /> <li>[callback:callbackFunction],<br /></li><br /><ul><br /> <li>[bind:[{event: function},{event:function} ] })<br /></li></ul></ul><strong><br />jQuery(imgElement).rotateAnimation</strong><br /><strong><br />Where:</strong><br /> <ul><li>- angleValue - clockwise rotation given in degrees,<br /></li><br /> <li>- [animateAngleValue] - optional parameter, animate rotating into this value,<br /></li><br /> <li>- [maxAngleValue] - optional parameter, maximum angle possible for animation,<br /></li><br /> <li>- [minAngleValue] - optional parameter, minimum angle possible for animation,<br /></li><br /> <li>- [callbackFunction] - optional function to run after animation complete,<br /></li><br /> <li>- [bind: [ {event: function}...] -optional parameter, list of events binded to newly created rotateable object<br /></li></ul><strong> Examples:</strong><br /><div class="CodeRay"><br /> $(document).ready(function()<br /> {<br /> $('#image').rotate(-25);<br /> <br /><br /> });<br /></div><br /><script type="text/javascript"><br /> $(document).ready(function()<br /> {<br /> $('#image').rotate(-25);<br /> $('#image2').rotate({angle:5}); <br /> var rot=$('#image3').rotate({maxAngle:50,minAngle:-55,<br /> bind:<br /> [<br /> {"mouseover":function(){rot[0].rotateAnimation(50);}},<br /> {"mouseout":function(){rot[0].rotateAnimation(-50);}}<br /> ]<br /> });<br /><br /><br /> });<br /></script><br /><img id="image" src="http://vikasnandal.heroku.com/images/1208.jpg" alt="vikas nandal" /><br /><br /><div class="CodeRay"><br />$(document).ready(function()<br /> {<br /> $('#image2').rotate({angle:5}); <br /> });<br /><br /></div><br /><br /><br /><div class="CodeRay"><br />$(document).ready(function()<br /> {<br /> var rot=$('#image3').rotate({maxAngle:50,minAngle:-55,<br /> bind:<br /> [<br /> {"mouseover":function(){rot[0].rotateAnimation(50);}},<br /> {"mouseout":function(){rot[0].rotateAnimation(-50);}}<br /> ]<br /> });<br /> });<br /><br /></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-65790818656638726212009-01-08T09:25:00.000-08:002009-06-11T02:17:05.718-07:00Ajax pagination with mislav's will_paginate<h3>Installation of mislav's will_paginate.</h3>In previous rails versions the PaginationHelper was in bilt but in later versions (Rails 2.0) it is deleted. There are two ways to install the will paginate.<br /> <ul><li>use the gem(recommended)<br /> </li><li>install as Rails plugin using git<br /></li></ul><br />I have put that in the vender/gems folder.<br />Here is the process :<br /><br /><h3>Gem Installation.<br /></h3><ol><li>Download the gem from the Git Hub :</li><code>git clone git://github.com/mislav/will_paginate.git</code><br /><br /><li>Put this in vender/gems folder.</li><br /><li>Put the following code in environment.rb file :</li><br /><code>config.gem "mislav-will_paginate", :version => "2.3.6", :lib => "will_paginate"</code><br /><li>Now in your controller write the code for pagination :</li><br /><div class="CodeRay"><br />def index<br /> @posts = Post.paginate(:all, :page => params[:page], :per_page => 6)<br /> respond_to do |format|<br /> format.html { }<br /> format.js {<br /> render :update do |page|<br /> page.replace_html 'all-posts', :partial => @posts<br /> page.replace_html 'pagination', :partial => 'pagination',<br /> :locals => {:collection => @posts}<br /> end<br /> }<br /> format.xml { render :xml => @posts }<br /> end<br />end<br /><br /></div><br /><br />There will be two partials one for showing the posts and other for the pagination helper.<br /><br /><li>The pagination partial will look like this : -<br /></li>pagination.html.erb :-<div class="CodeRay"><br /><%= will_paginate collection, :remote => "true", :params => { :paginated => true } %><br /><br /></div><br /><br /><li>The index.rhtml file will be :</li><br /><br />index.html.erb :-<br /><div class="CodeRay"><br /><br /><div id="all-posts"><br /><%= render :partial => @posts %><br /></div><br /><div id="pagination"><br /><%= will_paginate @posts, :remote => "true" %><br /></div><!-- pagination --><br /><br /></div><br /><br /></ol>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-1562052059706013773.post-83717662376445335962008-03-29T09:51:00.000-07:002008-04-04T21:03:33.051-07:00How to export data using MS word or MS excelIts also very easy to export data to doc format or xls format. There is no plugin or gem required for that.<br />The procedure is :<br /><br />FOR XLS FORMAT:<br /><br /><span style="font-weight:bold;"><br />def export<br /> headers['Content-Type'] = "application/vnd.ms-excel" <br /> headers['Content-Disposition'] = 'attachment; filename="excel-export.xls"'<br /> headers['Cache-Control'] = ''<br /> @records = Record.find(:all)<br />end<br /></span><br /><br />and <br /><br />FOR DOC FORMAT<br /><br /><span style="font-weight:bold;"><br />def export<br /> headers['Content-Type'] = "application/vnd.ms-word" <br /> headers['Content-Disposition'] = 'attachment; filename="excel-export.doc"'<br /> headers['Cache-Control'] = ''<br /> @records = Record.find(:all)<br />end<br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-24956653676798280922008-03-29T09:36:00.000-07:002008-03-29T09:51:28.339-07:00How to export data to CSV In Ruby on RailsThe exporting of data to CSV in Rails is very easy just like snitching icecream from 2 year baby. You just need to install a Gem for it and a method and its done.<br /><br />The procedure is written below:-<br /><br />1. install the fastercsv gem :-<br /><br /><span style="font-weight:bold;"> sudo gem install fastercsv</span><br /><br /><br />2. now in the controller use this gem and copy the method in the bottom of your controller and also use CSV as written:-<br /><br /><span style="font-weight:bold;"><br />class ArticlesController < ApplicationController<br /><br />require 'fastercsv'<br />......<br />.<br />.<br />.<br /><br />def show_users<br /> @users = User.find(:all)<br /> stream_csv do |csv|<br /> csv << ["Show all the users in excel"]<br /> csv << [""]<br /> csv << ["ID" ,"Name" ,"Address" ,"Email"]<br /> @users.each do |u|<br /> csv << [u.id, u.name, u.address, u.email]<br /> end<br /> end<br /><br />end<br /><br />private<br /> def stream_csv<br /> <br /> filename = action_name + ".csv" <br /><br /> #this is required if you want this to work with IE <br /> if request.env['HTTP_USER_AGENT'] =~ /msie/i<br /> headers['Pragma'] = 'public'<br /> headers["Content-type"] = "text/plain" <br /> headers['Cache-Control'] = 'no-cache, must-revalidate, post-check=0, pre-check=0'<br /> headers['Content-Disposition'] = "attachment; filename=\"#{filename}\"" <br /> headers['Expires'] = "0" <br /> else<br /> headers["Content-Type"] ||= 'text/csv'<br /> headers["Content-Disposition"] = "attachment; filename=\"#{filename}\"" <br /> end<br /><br /> render :text => Proc.new { |response, output|<br /> csv = FasterCSV.new(output, :row_sep => "\r\n") <br /> yield csv<br /> }<br /> end<br /><br />end<br /><br /><br /></span><br /><br />and its done. You have exported data to excel sheet .Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-1562052059706013773.post-81654821693151783152008-02-25T19:15:00.001-08:002008-02-25T19:25:54.979-08:00Installing Tata Indicom Modem in UbuntuIt is needed but Tata Indicom doesn't provide any CD to run USB VDATA card to run in Ubuntu(Linux)<br /><br />SO try these steps to install it in Ubuntu.<br /><br />1. Open a terminal window.<br />2. Enter as an root (type su (press enter) your password.)<br />3. Then use vi or nano or gedit to edit/create the following file /etc/wvdial.conf .<br />4. Enter the following text into it.<br /><span style="font-weight:bold;"> [Modem0]<br /> Modem=/dev/ttyUSB0<br /> Baud=115200<br /> SetVolume=0<br /> Dial Command = ATDT<br /> init1=ATZ<br /> init2=AT+CRM=1<br /> FlowControl= Hardware (CRTSCTS)<br /> [Dialer tata]<br /> Username= internet<br /> Password= internet<br /> Phone=#777<br /> Stupid Mode= 1<br /> Inherits = Modem0</span><br /><br />5. Then create /etc/resolv.conf using vi or nano with sudo <br />type: nameserver 202.138.103.100 <br /> nameserver 202.138.96.2<br /><br />6. THIS SPECIFIES THE PRIMARY AND SECONDARY DNS SERVERS.<br />Then in terminal type <br /><span style="font-weight:bold;">sudo wvdial tata</span><br /><br />So now your Tata Indicom Vdata Card is installed.<br /><br />Similary you can install USB Modem of tata indiacom :<br /><br />just open the terminal<br />and enter as a root <br />and vi or nano or gedit to edit/create the following file /etc/wvdial.conf .<br /><br /><span style="font-weight:bold;">[Dialer Defaults]<br />Modem = /dev/ttyACM0<br />Baud = 460800<br />Init1 = ATZ<br />Init2 = ATQ0 V1 E1 S0=0 &C1 &D2<br />+FCLASS=0<br />ISDN = 0<br />Modem Type = USB Modem<br />Phone = #777<br />Username = internet<br />Password = internet<br />stupid mode = 1</span><br /><br /><br /> save it and run sudo wvdial<br /><br />If you are a reliance user then<br />just change the phone ,username and password<br /><span style="font-weight:bold;"><br />Phone = #777 <br />Username = <phone no><br />Password = <phone no></span><br /><br />and Bingoo!!!Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-63543096669256475322008-02-25T01:55:00.000-08:002008-02-25T02:45:41.929-08:00Uploading video using Mongrel_upload progress and Active MessagingActiveMessaging is an attempt to bring the simplicity and elegance of rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc.<br /><br />Download Active Messaging from SVN:<br /><br /><span style="font-weight:bold;">script/plugin install http://activemessaging.googlecode.com/svn/trunk/plugins/activemessaging </span><br /><br />For the protocol, ActiveMessaging supports Stomp: Streaming Text-Oriented Messaging Protocol. Stomp is a messaging standard to exchange text based messages over wire connections, usually tcp/ip.<br /><br />TO install the stomp install the gems:<br /><br />Assuming you have Rails 1.1+ and MySql already, you'll also need 2 more RubyGems: daemons and Stomp:<br /><br /><span style="font-weight:bold;">sudo gem install daemons<br />sudo gem install stomp</span> <br /><br />Download Apache ActiveMQ from <br /><span style="font-weight:bold;">http://activemq.apache.org/</span><br /><br />Apache ActiveMQ is the most popular and powerful open source Message Broker and Enterprise Integration Patterns provider.<br /><span style="font-weight:bold;"><br />cd /usr/local/src<br /> #unix and cygwin<br /> wget http://people.apache.org/repo/m2-snapshot-repository/org/apache/activemq/apache-activemq/4.2-SNAPSHOT/apache-activemq-4.2-20070221.081507-10-src.tar.gz<br />#os x<br />curl -O http://people.apache.org/repo/m2-snapshot-repository/org/apache/activemq/apache-activemq/4.2-SNAPSHOT/apache-activemq-4.2-20070221.081507-10-src.tar.gz<br /> <br />cd ..<br />tar xvfz apache-activemq-4.2-20070221.081507-10-src.tar.gz<br />cd apache-activemq-4.2-incubator-SNAPSHOT<br /> ./bin/activemq </span><br /><br /><br /><br />Download the sample application using ActiveMessaging and Amazon S3<br /><br /><span style="font-weight:bold;">http://blog.snowonrails.com/articles/2007/05/31/how-to-build-a-mini-youtube-using-activemessaging-plugin-and-amazon-s3</span><br /><br /><br /><br />Mongrel Upload Demo<br />http://itblog.mcgeecorp.com/2007/5/15/mongrel-upload-progress-demo<br /><br /><br />Install the mongrel_upload progress plugin<br /><br />gem install mongrel --source=http://mongrel.rubyforge.org/releases/<br /><br />svn co svn://rubyforge.org/var/svn/mongrel/trunk/projects/mongrel_upload_progress<br />cd mongrel_upload_progress<br />rake install<br /><br /><br /><br />Mongrel_upload useses respond_to_parent function and also mongrel_upload_progress.conf file<br /><br />Now Active Messaging video uploading as give by the <br /><br /><a href="http://blog.snowonrails.com/articles/2007/05/31/how-to-build-a-mini-youtube-using-activemessaging-plugin-and-amazon-s3"></a><br /><br />uses the Amazon S3 address for string the file address. And for that you need API key<br />and for sure its not free. So I have discovered the alternate to use the localhost for stroing the images.<br /><br />Its very simple..<br /><br />In the model video.rb use the following:<br /><br /><span style="font-weight:bold;"> VIDEO_BASE = "#{RAILS_ROOT}/public/videos"<br /> VIDEO_UPLOADED = VIDEO_BASE+"/uploaded/"<br /> VIDEO_CONVERTED = VIDEO_BASE+"/converted/"</span><br /><br /><span style="font-weight:bold;">def video=(video_file)<br /> @temp_file = video_file<br /> self.file_name = video_file.original_filename<br /> self.ext = self.file_name.split('.').last<br /> end<br /> <br /> def video_upload_path(file_name=self.file_name)<br /> VIDEO_UPLOADED + file_name<br /> end<br /><br /> def video_convert_path(file_name=convert_file_name) <br /> VIDEO_CONVERTED + "#{id}/"+ file_name <br /> end<br /> <br /> def convert_file_name<br /> "#{get_original_filename_without_ext}.flv"<br /> end<br /> <br /> def before_create<br /> logger.debug("In before save of video.rb, video_upload_path is:"+video_upload_path+" and video_convert_path is:"+video_convert_path)<br /> save_upload_file<br /> end<br /> <br /> def after_create<br /> create_dir<br /> end<br /> <br /> private<br /> def get_original_filename_without_ext(filename=self.file_name)<br /> filename.sub(/(.\w+\z)/,"")<br /> end<br /> <br /> def create_dir<br /> if !File.exist?(VIDEO_CONVERTED+"#{id}/")<br /> Dir.mkdir(VIDEO_CONVERTED+"#{id}/")<br /> end<br /> end<br /> <br /> def save_upload_file<br /> if !File.exist?(VIDEO_BASE)<br /> Dir.mkdir(VIDEO_BASE)<br /> end<br /> if !File.exist?(VIDEO_UPLOADED)<br /> Dir.mkdir(VIDEO_UPLOADED)<br /> end<br /> if !File.exist?(VIDEO_CONVERTED+"#{id}/")<br /> Dir.mkdir(VIDEO_CONVERTED+"#{id}/")<br /> end<br /> <br /> File.open(video_upload_path,"wb") do |f|<br /> f.write(@temp_file.read)<br /> end<br /> end</span><br /><br /><br />In the broker.yml file use the following settings:<br /><br /><span style="font-weight:bold;"> adapter: stomp<br /> login: ""<br /> passcode: ""<br /> host: localhost<br /> port: 61613<br /> reliable: true<br /> reconnectDelay: 5</span><br /><br /><br />Now its done.<br /><br />Start your newly created application as like that:<br /><br />Start ActiveMQ<br />Start Rails with mongrel_upload_progress config file<br />Start Poller<br />Start DRB server<br /><br />Bingoooooooooo.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-66811171009527372042008-02-24T10:58:00.000-08:002008-02-24T11:04:15.758-08:00Adding Tags without spacesSome times it is needed to addd the tag using acts_as_taggable plugin that you don't need spaces while creating tags. Means the tags are seprated not by spaces but with commas(,). For the we have to modify the code in the acts_as_taggable plugin. <br /><br />Just open the file \vendor\plugins\acts_as_taggable\lib\tag.rb<br /><br />We have to midify the method <span style="font-weight:bold;">self.parse(list)</span><br /><br />with the following code:<br /><br /><span style="font-weight:bold;">def self.parse(list)<br /> unless list.kind_of? Array<br /> tag_names = []<br /><br /> # first, pull out the quoted tags<br /> list.gsub!(/"(.*?)"s*/ ) { tag_names << $1; "" }<br /><br /> # then, replace all commas with a space<br /> list.gsub!(/,/, " ")<br /><br /> # then, get whatever's left<br /> tag_names.concat list.split(/s/)<br /><br /> # strip whitespace from the names<br /> tag_names = tag_names.map { |t| t.strip }<br /><br /> # delete any blank tag names<br /> tag_names = tag_names.delete_if { |t| t.empty? }<br /><br /> return tag_names<br /> else<br /> tag_names = list.collect {|tag| tag.nil? ? nil : tag.to_s}<br /> return tag_names.compact<br /> end<br /> end</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-29219305298787089972008-02-24T09:42:00.000-08:002008-02-24T10:06:19.989-08:00Creating Tag Cloud using acts_as_taggableIn you rails application if you are using acts_as_taggable plugin for creating tags you often need to use tag cloud. To create a tag cloud using acts_as_taggable plugin its simple. We need to add some code in tagaable plugin.<br /><br />It is as follows:<br />Add a new method in the Tag model provided by the acts_as_taggable plugin. Open the vendor/plugins/acts_as_taggable/lib/tag.rb file and add the following method:<br /><span style="font-weight:bold;"><br />def self.tags(options = {})<br /> query = "select tags.id, name, count(*) as count"<br /> query << " from taggings, tags"<br /> query << " where tags.id = tag_id"<br /> query << " group by tag_id"<br /> query << " order by #{options[:order]}" if options[:order] != nil<br /> query << " limit #{options[:limit]}" if options[:limit] != nil<br /> tags = Tag.find_by_sql(query)<br />end</span><br /><br /><br />This method will return the id, name, and usage count for each tag. This method also provides a way to limit and order the tags. Once we have added the new method in the Tag model we will need to add a method to the application helper which will help in selecting the right style class for each tag. Add the following function to app/helpers/application_helper.rb:<br /><br /><br /><span style="font-weight:bold;">def tag_cloud(tags, classes)<br /> max, min = 0, 0<br /> tags.each { |t|<br /> max = t.count.to_i if t.count.to_i > max<br /> min = t.count.to_i if t.count.to_i < min<br /> }<br /><br /> divisor = ((max - min) / classes.size) + 1<br /><br /> tags.each { |t|<br /> yield t.name, classes[(t.count.to_i - min) / divisor]<br /> }<br />end</span><br /><br />Now focus on the controller and view. In the controller you can use the following bit of code to get the the first one hundred tags order by name:<br /><span style="font-weight:bold;"><br />@tags = Tag.tags(:limit => 100, :order => "name desc")</span><br /><br />In the view we will use the tag_cloud method so that it will select the right css class based on the tag usage count. Here is the view code:<br /><span style="font-weight:bold;"><% tag_cloud @tags, %w(nube1 nube2 nube3 nube4 nube5) do |name, css_class| %><br /> <%= link_to name, {:action => :tag, :id => name},<br /> :class => css_class %><br /><% end %></span><br /><br />In the Css file add the following line.<br /><br /><span style="font-weight:bold;"><span style="font-style:italic;">.nube1,.nube1:hover, .nube1:active, .nube1:visited </span>{text-decoration:underline;font-size: 1.2em;font-weight: 100;margin-left:1px;color:#000000;}<br /><span style="font-style:italic;">.nube2,.nube2:hover, .nube2:active, .nube2:visited </span>{text-decoration:underline;font-size: 1.4em;font-weight: 300;margin-left:1px;color:#000000;}<br /><span style="font-style:italic;">.nube3,.nube3:hover, .nube3:active, .nube3:visited </span>{text-decoration:underline;font-size: 1.6em;font-weight: 500;margin-left:1px;color:#000000;}<br /><span style="font-style:italic;">.nube4,.nube4:hover, .nube4:active, .nube4:visited </span>{text-decoration:underline;font-size: 1.9em;font-weight: 700;margin-left:1px;color:#000000;}<br /><span style="font-style:italic;">.nube5,.nube5:hover, .nube5:active, .nube5:visited </span>{text-decoration:underline;font-size: 2.2em;font-weight: 900;margin-left:1px;color:#000000;}<br /><span style="font-style:italic;">.nube6,.nube6:hover, .nube6:active, .nube6:visited </span>{text-decoration:underline;font-size: 2.5em;font-weight: 1100;margin-left:1px;color:#000000;}<br /><br /></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-68851523730531798182008-02-24T04:23:00.000-08:002008-02-24T07:36:47.816-08:00Observe_form for getting Live previewYou’d like to give your users the ability to see a live preview of their data<br />as they are editing it. You don’t want them to have to wait until they<br />submit a form. So that if there is any error it can be rectified.<br /><br />Include the javascripts in the layouts.<br /><br /><span style="font-weight:bold;"><%= javascript_include_tag "default" %></span><br /><br />Now that we’ve got the necessary JavaScript libraries loaded, we’ll create<br />the model and controller.Suppose the controller name is Content and model name is Example. There are two fields in the table ('title' and 'body' )<br /><br />Now in the model define the attribute accessor<br /><br /><span style="font-weight:bold;">class Example<br />attr_accessor :title, :body<br />end</span><br /><br />We will create a new method <br /><br /><span style="font-weight:bold;">def new<br />@data= Example.new<br />end</span><br /><br /><br />Create the file, app/views/content/new.rhtml, and edit it to look like<br />the following.<br /><span style="font-weight:bold;"><br /><% form_for(:example,:url => {:action=>'create',:html => {:class=>'wufoo', :id => "form"} ) do |form| %><br /><%= text_field :example, :title %><br /><br /><%= text_area :example, :body %><br /><br /><%= submit_tag "Save" %><br /><% end %><br /><%= observe_form "form",<br />:frequency => 5,<br />:update => "preview",<br />:complete => "Element.show(' preview' )",<br />:url => { :action => "preview" } %><br /><div id="preview" style="display: none; border: 1px solid"></div></span><br /><br />In the method preview we write<br /><br /><span style="font-weight:bold;">def preview<br />render :layout => false<br />end<br /><br /></span><br /><br />The only job of the action code is to short circuit the application’s usual<br />rendering. Since we’re going to be updating the live-preview element of<br />our diary entry creation page with the full results of the preview( ) action,<br />we don’t want it returning a full HTML page.<br /><br />The preview action’s view, in app/views/content/preview.rhtml should look<br />like this:<br /><span style="font-weight:bold;"><h2>Form Preview</h2><br /><h3><%= params[:example][:title] %></h3><br /><%= textilize params[:example][:body] %></span><br /><br />That’s all there is to it! This view prints the entry’s title as an HTML<br />heading and then generates HTML output via the textilize( ) method. This<br />method uses the RedCloth library internally to transform very simple<br />text markup to HTML.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-6087417593197021922008-02-24T03:39:00.000-08:002008-02-24T07:41:53.273-08:00Ajax Editing using In-Place Form EditingYour application has data that are often edited by<br />your users—usually very quickly. You want to give your users an easy<br />way to edit application data in place without having to open a separate<br />editing form.<br /><br />Rails makes in-place editing easy with the script.aculo.us InPlaceEditor<br />control and accompanying helpers.<br /><br />First create a model and controller.<br /><br />Put JavaScript files in your views. Somewhere in the head<br />of your HTML document, you can call the following:<br /><br /><span style="font-weight:bold;"><%=javascript_include_tag :defaults%></span><br /><br />put the in place editor in you .rhtml file like this<br /><br /><br /><span style="font-weight:bold;"><%=in_place_editor_field :contact, :name%></span><br /><br /><br />In Controller write the following line<br />in_place_edit_for :contact, :name<br /><br />and its done.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-1562052059706013773.post-22264625024732528852008-02-24T01:51:00.000-08:002008-02-24T09:42:25.550-08:00Ajax Pagination in railsAjax Pagination in Rails is very simple and DRY. You Just have to put ajax helper method in applicartion .rb. And its done. Here is the procedure.:<br /><br />1) Put the following line of code in apllication_helper.rb file.<br /><br /><span style="font-weight:bold;">def ajax_pagination_links(paginator, options={})<br /><br />options.merge!(ActionView::Helpers::PaginationHelper::DEFAULT_OPTIONS) {key, old, new old}<br />window_pages = paginator.current.window(options[:window_size]).pages<br />return if window_pages.length <= 1 unless options[:link_to_current_page] first, last = paginator.first, paginator.last returning html = '' do if options[:always_show_anchors] and not window_pages[0].first? html << update =""> options[:update], :url => { options[:name] => first }.update(options[:params] ))<br />html << ' ... ' if window_pages[0].number - first.number > 1<br />html << ' ' end window_pages.each do page if paginator.current == page && !options[:link_to_current_page] html << update =""> options[:update], :url => { options[:name] => page }.update(options[:params] ))<br />end<br />html << ' ' end if options[:always_show_anchors] && !window_pages.last.last? html << ' ... ' if last.number - window_pages[-1].number > 1<br />html << update =""> options[:update], :url => { options[:name] => last }.update( options[:params]))<br />end<br />end<br />end</span><br /><br /><br />2) Now in the controller in you method put the following code.<br /><br /><span style="font-weight:bold;">def user<br />@content_pages, @contentdata = paginate :users, :order =>"create_date DESC", :per_page => 6<br />if params[:page]<br />render :update do page<br />page[:center].replace_html :partial=>'user'<br />end<br />else<br />render :action=>'user'<br />end<br />end</span><br /><br /><br />3) And in the last just put these lines in the view part (rhtml) and its done.<br /><br /><br /><span style="font-weight:bold;"><br /><%=ajax_pagination_links @content_pages, {:params => {:search_query => @params[:search_query]} }%></span>Unknownnoreply@blogger.com0