plugin in rails · RubyonRails

Will Paginate — Plugin

Will Paginate:

1. Installation:

cmd>git clone git://github.com/mislav/will_paginate.git

2. Git Installation

You don’t have git installed already then install it

Install git from here.

3. Try with this Basic Code:

a. Product model(products Table) contains these fields

id
name
price
description

b. DB has 100 records

c. controller:

def productlist
@products = Product.paginate :page => params[:page]
end

d. productlist.hml.erb

<%= will_paginate @products %>

<ul>
<% @products.each do |c| %>
<li><%= c.id %> – <%= c.name %> – <%= c.price %> – <%=
c.description %></li>
<% end %>
</ul>

Output looks Like:

Links for more help –> http://agilewebdevelopment.com/plugins/will_paginate

Advertisements
AjaxOnRails · plugin in rails · RubyonRails

Active scaffold – Rails plugin

Active Scaffold

Active scaffold is rails plugin used for,

Create,Edit,Update,delete,Search and sorting records in Ajax.

If you want to install it in your rails application then,

1. Please follow this url –> Active Scaffold

2. Install git in your computer –> Git

Ruby · RubyonRails

Console commands in Ruby(Windows)

Hi All,

Sorry for a big gap…

Command Prompt commands in Ruby:(Windows Only)

Goto Command prompt:

c:> ipconfig

It will gives the details about ur ip address.How can i get the same from Ruby code.

system(‘ipconfig’)

Output:

Windows IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :

IP Address. . . . . . . . . . . . : 192.168.1.25

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.1.1

Program 2:

commandprompt.rb

system(‘ping 192.168.1.1’)
puts “———————”
system(‘ipconfig’)

>ruby commandprompt.rb

Pinging 192.168.1.1 with 32 bytes of data:

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.1.1:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

———————

Windows IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :

IP Address. . . . . . . . . . . . : 192.168.1.25

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.1.1

>Exit code: 0

Program3:

Shutdown,restart,logoff your windows machine using Ruby codes.

shutdown.rb

system(‘shutdown.exe’)

Output:

Usage: shutdown.exe [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-
c “comment”] [-d up:xx:yy]

No args Display this message (same as -?)
-i Display GUI interface, must be the first option
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a Abort a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c “comment” Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without war
ning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer le
ss than 256)
yy is the minor reason code (positive integer le
ss than 65536)

shutdown.rb

system(‘shutdown.exe -r -f -t 0’)

Run it…

Output:

System shutdown in default.

Reference:

http://rubyonwindows.blogspot.com/

http://www.ruby-forum.com/topic/150301

RubyonRails · Testing · watir

Watir Cheat sheet

Watir Cheat Sheet

 

Getting Started with Watir

require ‘watir’

Load the Watir library

ie = Watir::IE.start

(‘http://localhost:8080&#8217;)

Start IE using the local timeclock server.

ie.close

Close IE.

ie = Watir::IE.attach(:title, ‘title‘)

Attach to an existing IE window, so you can drive it with Watir.

 

Manipulating Controls with Watir

ie.text_field(:name, ‘name‘).set(‘value‘)

Set the text field specified name specified value.

ie.button(:value, ‘value‘).click

Click the button with the specified value (label)

ie.button(:name, ‘name‘).click

Click the button with the specified name.

ie.checkbox(:name, ‘name‘).set

Check the check box named “name”. (Uncheck: clear)

ie.object(:attribute, ‘name‘).flash

Cause the specified control to flash.

 

A Special Testing Function For Timeclock

 

require ‘toolkit/testhook’

ensure_no_user_data ‘name

Delete any database records for the named user.

 

Accessing Page Contents with Watir

ie.contains_text(‘text‘)

Return true if the current page has the specified text somewhere on the page. Otherwise, false.

ie.title

Return the title of the current page.

ie.html

Return all the HTML in the body of the page

ie.table(:id, ‘recent_records).to_a

Return an array containing the text in the table’s rows and columns.

ie.table(:id, ‘recent_records’)[2][1].text

Return the text from the first column of the second row of the table id’d ‘recent_records.

 

Assertions

assert_equal(expected, test_method)

Test whether the expected value matches the actual value returned by the test method

assert_match(regexp, test_method)

Test whether the regular expression matches the actual value returned by the test method.

assert(expression)

Test whether the expression is true.

plugin in rails · RubyonRails

Ferret in rails

View

<%= start_form_tag :action => ‘search_number’ %>

<div align=”center”>
<h3>Search Phonenumber By</h3>
<table>
<tr>

<td><select name=”searchfield” prompt=”select”>
<option selected>select</option>
<option value=”phonenumber” >Phonenumber</option>
<option value=”name” >Name</option>
<option value=”city” >City</option>
</select>
</td>
<td>
<%= text_field_tag ‘searchkey’ %>
<%= submit_tag “Search” %>

</tr>
</table>
</div>

<%= end_form_tag %>

Controller:

def search_number
if params[:searchfield]
session[:field]= params[:searchfield]
end
field = session[:field]

if params[:searchkey]
session[:query] = params[:searchkey]
end
query= session[:query]
@total, @phones = User.full_text_search(field,query, :page => (params[:page]||1))
@pages = pages_for(@total)
if @phones.length > 0
render :action=>’search_number’
else
render :text=>’No Result’
end

end

RubyonRails

Profile Updation in Rails

Account Controller –>

session[:user_id]= self.current_user.id

HOME Controller inside:

def list
end

def search
@user = User.find(session[:user_id])
if @user.update_attributes (params[:user])
flash[:notice] = ‘User Name was successfully updated.’
redirect_to :action => ‘index’, :id => @user
else
redirect_to :action => ‘list’
end

end

LIST.RHTML

<%= start_form_tag :action => ‘search’ %>
<%= text_field ‘user’,’name’ %>
<%= text_field ‘user’,’age’ %>
<%= submit_tag ‘Update Profile’ %>

<% end_form_tag %>

INDEX.RHTML

<%= flash[:notice] %>

RubyonRails

Pagination in Rails

Pagination :

Inside method

if params[:Pincode]
session[:location] = params[:Pincode]
end
location = session[:location]
# @locations_pages, @locations = paginate :companies, :per_page =>2, :conditions=>[“location like ?”, “%#{location}%”]

@locations_pages, @zipdetail = paginate :zipdatas, :per_page =>5,:conditions  =>[“Pincode like?”,”%#{location}%”]

View :

<% for c in @zipdetail %>
<table border=’1′>
<tr><td> <%= c.Pincode %> </td>
<td> <%= c.OfficeName %> </td>
<td> <%= c.Status %> </td>
<td> <%= c.Suboffice %> </td>
<td> <%= c.HeadOffice %> </td>
<td> <%= c.OfficeName %> </td>
<td> <%= c.Location %> </td>
<td> <%= c.Telephone %> </td>
<td> <%= c.SPCC %> </td>
<td> <%= c.Postal %> </td>
<td> <%= c.Division %> </td>
<td> <%= c.Region %> </td>
<td> **************** </td>

</tr>
</table>
<% end %>

<%= link_to ‘[previous]’, { :page => @locations_pages.current

.previous } \
if @locations_pages.current.previous %>
<%= pagination_links(@locations_pages) %>
<%= link_to ‘[next]’, { :page => @locations_pages.current.next } \
if @locations_pages.current.next %>

<%= link_to ‘Back to Search’, :action => ‘show’ %>
<%= link_to ‘Home Page’, {:action => ‘index’, :controller => ‘home’}, {:accesskey => 3} %>