I had installed Rails 3.0 on my Ruby 1.9.2 system and was trying out a new app. I had the mysql gem already installed into my system and hence since we know by default rails creates sqlite based database.yml. Hence forth while creating the file, I had to do the following changes

$rails new testmysqlapp -d mysql

This creates a mysql based app. however by default when you open the database.yml, you will see the adapter as mysql2 instead of mysql. I just changed from mysql2 to mysql

development:
adapter: mysql (changed from mysql)
encoding: utf8
database: testmysqlapp_development
pool: 5
username: root
password:
host: localhost

Also if you look at the GEMFILE you will see gem ‘mysql’ already available.

Now the first thing you do is run bundle installer

$cd testmysqlapp
$bundle install

This will install all the gems that you want to use.  Next step is to create the database. Lets use the standard rake method

$rake db:create (sometimes this will give errors especially i have found it in rails 3.0.1).

So alternatively i have used

$rake -r mysql db:create

Everything works fine and the database is created. this generally creates the Test and Development databases. Alternatively you can also mention the environment as

$rake -r mysql db:create ENV=development

Similarly when you want to do the migration you can call the similar code

$rake -r mysql db:migrate ENV=development

Hope this helps someother person… I have wasted whole day finding solution for this…

 

Introduction

There has been so many plugins in ruby on rails space and we have been always re-inventing the wheel and writing again and again… Why do we do that? One of the main reasons are that many plugins have been built are for particular reasons and they haven’t integrated them. One of the similar plugins I am talking is about the country_select and state_select. One is used to select the countries and another to select the state. What happened to the regions…should we write one more plugin to say region_select or continent_select? …. This motivated me to integrate all the plugins so that we have one plugin… When I started to write the geography_division_select I had in mind that I want to integrate regions, countries and states. But by the time implementation completed I had added multiple features such as conditioins, priority list and selected options.

what does GEOGRAPHY_DIVISION_SELECT do?

Geography Division Select is a select tag which helps developers to display all divisions of the World. This plugin is similar to the country_select and state_select plugins and includes both mechanisms.

 

  1. Using Geography Division Select a user can
  2. List all the Regions (Continents) of the world (based on conditions)
  3. List all the Countries of the world (based on conditions)
  4. List all the States/Provinces/Districts…etc., for Each(or more) Country(ies)(based on conditions)
  5. Provide drill downs based on :o nly and :exclude conditions
  6. Support Priority Listing
  7. Support preselected listing

 

Geography Division Select can be used by 4 methods

 

  1. By using geography_division_select with object and method and option. This creates a HTML SELECT tag along with OPTION tags
  2. By using rails select_tag and sending the options by use of geography_division_options_for_select
  3. By using HTML SELECT tag and wrapping around Option Tags  by use of geography_division_options_for_select.
  4. By using geography_division_select as part of Form Tag.

 

Who are the authors of acts_as_fannable?

Satish Kota. He is the founder and chief technical architect of Heurion Consulting Pvt Ltd. A small RoR shop based in Bangalore, India. We have been providing exciting RoR services. Visit our website www.heurionconsulting.com

Where is Geography_division_select plugin available?

It is available in git. The public clone to this git is

git clone git://github.com/heurionconsulting/geography_division_select.git

How to use geography_division_select ?

 

Geography Division select can be used in 2 methods

 

1. Select tag which generates the HTML SELECT and OPTION TAGS

 

geography_division_select(object,method,options,html_options)

 

2. Select tag which generates just OPTION TAGS which can be wrapped around a HTML SELECT TAG

 

geography_division_options_for_select(options)

 

The main entity that controls the display of geography_division_select is the options section. The main supporting elements are

 

:drilldown — This keyword identifies the type of data to be shown as part of dropdown. Supporting types of drilldown are

            :drilldown=>”region” — displays the regions (continents) of the world based on conditions. This is the default type of drilldown

            :drilldown=>”country” – displays the countries of the world based on conditions

            :drilldown=”state” – displays the states/provinces/atolls/islands,etc., of a country(ies) based on conditions

 

:selected – This keyword identifies which option in the dropdown has to be preselected.

 

:priority – This keyword identifies if there is any priority selection that has to be provided along with the complete list.

This helps if the developer wants to ensure priority for a particular country/state/region.

 

:o nly – This keyword provides support to identify conditions for the drilldown to provide display of that particular or set of drilldown elements.

Only Conditions has to be used in conjunction of the drilldown type to identify better selection of drilldown data.

 

:exclude — This keyword provides support to exclude a list of options while creating the dropdown options. Just like :o nly conditions, :exclude conditons

can be used in conjunction of the drilldown types to allow better selection of drilldown data.

 

NOTE: 

 

1. :o nly and :exclude conditions can have multiple drilldowns as part of the conditions. It helps in making correct query of options that are displayed

 

e.g.       a. :o nly=>{:country=>”United States Of America”,:region=>”North America”}

            b. :exclude=>{:country=>”India”, :state=>”Karnataka”}

 

2. For any select tag both :o nly and :exclude can be used together.

 

e.g. {:only=>{:region=>”Asia”,:country=>”India”},:exclude{:state=>”Karnataka”}}

 

3. Any conditions either in :o nly or :exclude you can use multiple elements (separated by comma)

 

e.g.       a. :o nly=>{:country=>”India,United States of America, United Kingdom,France,Spain”}

            b. :exclude=>{:region=>”Africa,Asia,North America”}

            c. :o nly=>{:region=>”Asia,Africa,North America”},:exclude=>{:country=>”India,United States Of America,South Africa”}

 

4. By using Only conditions care has to be taken to ensure that the parent of the drilldown would be neglected. The various options are

            a. only has region drilldown — both country and state are considered if they are part of :exclude condition

            b. only has country drilldown — only state is considered if it is part of :exclude condition. if region is part of :o nly or :exclude condition it is not considered for calculation of states

            c. only has state drilldown — only the state is considered. If region or country is part of :o nly or :exclude condition, they are neglected for calculation of list of states

 

e.g.       a. :o nly=>{:region=>”Asia”},:exclude=>{:country=>”India”,:state=>”Karnataka”} — Valid

            b. :o nly=>{:country=>”India”},:exclude=>{:region=”North America”} — same as :o nly=>{:country=>”India”}

            c. :o nly=>{:region=>”Asia”,:country=>”India”} — same as :o nly=>{:country=>”India”}

            d. :o nly=>{:state=>”Washington”},:exclude=>{:region=>”Asia”} — same as :o nly=>{:state=>”Washington”}

            e. :o nly=>{:state=>”Washington”},:exclude=>{:region=>”Asia”,:country=>”United States of America”} — same as :o nly=>{:state=>”Washington”}

            e. :o nly=>{:country=>”United States of America”,:state=>”Washington”},:exclude=>{:region=>”Asia”}– same as :o nly=>{:state=>”Washington”}

            f. :o nly=>{:region=>”North America”,:state=>”New York”},:exclude=>{:country=>”United States of America”}– same as :o nly=>{:state=>”New York”}

            g. :o nly=>{:region=>”North America”,:country=>”United States of America”,:state=>”New York”} — same as :o nly=>{:state=>”New York”}

Thats it you are ready to use the plugin.

Any Examples?

Currently as part of the Read me file, I have listed about 20 examples, but till date there are about 38 different combinations that can be created. The first 20 examples are listed below for your perusal.

<p>

=======================================================================<br/>

You can just copy and paste all these examples in a view (rhtml or html.erb file) to get a better understanding of the options <br/>

=======================================================================

</p>

 

<p>Examples using geography_division_select tag<br/>

============================================

 

<p>Example 1: Default Entity

<%= geography_division_select(“geography”,”geography”) %></p>

Displays all the 7 regionsof the world

 

 

 

<p>Example 2: Region DrillDown

<%= geography_division_select(“geography”,”geography”,:drilldown=>”region”) %></p>

Displays all the 7 regions of the world

 

 

 

<p>Example 3: Region Drilldown using Region Only Conditions

<%= geography_division_select(“geography”,”geography”,:drilldown=>”region”,:only=>{:region=>”Europe,North America,South America”}) %></p>

Displays the 3 regions as set in the :o nly conditions

 

 

 

<p>Example 4: Region Drilldown using Region Exclude Conditions

<%= geography_division_select(“geography”,”geography”,:drilldown=>”country”,:exclude=>{:region=>”North America,South America”}) %></p>

Displays the all the regions of the world except regions declared in :exclude condition

</p>

 

 

 

<p>Examples using the normal select tag and geography_division_options_for_select <br/>

======================================================================

 

 

 

<p>Example 5: Country Drilldown

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”)) %></p>

Displays all the countries in the world

 

 

 

<p>Example 6: Country Drilldown with Country Only Conditions

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”,:only=>{:country=>”India,United States of America,United Kingdom”})) %></p>

Displays only the countries as listed in the :o nly conditions

 

 

 

<p>Example 7: Country Drilldown with Country Exclude Conditions

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”,:exclude=>{:country=>”India,United States of America,United Kingdom”})) %></p>

Displays all the countries in the world except the ones listed in the :exclude conditions

 

 

 

<p>Example 8: Country Type Region Only Conditions

<%= select_tag(“geography”,geography_division_options_for_select(:drilldown=>”country”,:only=>{:region=>”Asia,Europe”})) %></p>

Displays all the countries in the Asia and Europe Region.

 

</p>

<p>Examples using the geography_division_select as part of the form tag<br/>

=====================================================================

 

<% form_for :user do |f| -%>

 

<p><label for=”region”>Example 9: Country Drilldown using Region in Exclude Conditions</label><br/>

<%= f.geography_division_select :geography,:drilldown=>”country”,:exclude=>{:region=>”Asia,Europe”} %></p>

Displays all the countries in the world except the countries in the asia and europe region

 

 

 

<p><label for=”region”>Example 10: Country Drilldown using Region and Country in Only Conditions</label><br/>

<%= f.geography_division_select(“geography1″, :drilldown=>”country”,:only=>{:region=>”Asia,Europe”,:country=>”India,UnitedKingdom,France,Indonesia”}) %>

</p>

Displays all the countries as available in the :o nly conditions

 

 

 

<p><label for=”region”>Example 11: Country Drilldown using Region in Only and Country in Exclude Conditions</label><br/>

<%= f.geography_division_select :geography2, :drilldown=>”country”,:only=>{:region=>”Asia,Europe”},:exclude=>{:country=>”India,UnitedKingdom,France,Indonesia”} %></p>

Displays all the countries in the Asia and Europe Region except the countries listed in the :exclude conditions

 

 

 

<p><label for=”country”>Example 12: Country Drilldown using Region in Exclude and Country in Only Conditions</label><br/>

<%= f.geography_division_select :geography3,:drilldown=>”country”,:exclude=>{:region=>”Asia,South America”},:only=>{:country=>”India,Japan,South Africa”} %></p>

Displays all the countries listed in the :o nly conditions

 

 

 

<p><label for=”country”>Example 13: Country Drilldown using Region and Country in Exclude Conditions</label><br/>

<%= f.geography_division_select :geography4,:drilldown=>”country”,:exclude=>{:region=>”Asia,South America”,:country=>”France,United States of America,United Kingdom”} %></p>

Displays all the countries which are not part of Asia and South America regions and the countries listed in the :country exclude section.

 

 

 

<p><%= submit_tag ‘Submit’ %></p>

 

<% end -%>

</p>

 

<p>Examples using the HTML SELECT TAGS with options created using geography_division_options_for_select <br/>

 

 

 

<p>Example 14: State Drilldown using Country only State only Conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India”,:state=>”Karnataka,Delhi,Himachal Pradesh”}) %></select>

</p>

Displays all the states listed in the state’s only condition

 

 

 

<p>Example 15: State Drilldown using Country in Only and State in Exclude Conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India”},:exclude=>{:state=>”Karnataka,Himachal Pradesh”}) %></select>

</p>

Displays all the states of India  country excluding the states listed in the :exclude conditions

 

 

 

<p>Example 16: State Drilldown using Country in Exclude and State in Only Conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:exclude=>{:country=>”India”},:only=>{:state=>”Karnataka,Himachal Pradesh”}) %></select>

</p>

Displays all the states as listed in the Only conditions

 

 

 

<p>Example 17: State Drilldown using Country in Only conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India”}) %></select>

</p>

Displays all the states of India

 

 

 

<p>Example 18: State Drilldown using Country in Only conditions

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India,United Kingdom”}) %></select>

</p>

Displays all the states of India and United Kingdom

 

</p>

 

<p>Examples using the Selected option<br/>

====================================

 

<p>Example 19: State Drilldown using Country in Only conditions and Selected

<select name=”geography”>

<%= geography_division_options_for_select(:drilldown=>”state”,:only=>{:country=>”India,United Kingdom”},:selected=>”Greater London”) %></select>

</p>

Displays all the states of India and United Kingdom with London being selected

 

</p>

 

<p>Examples using the priority option<br/>

====================================

 

<p>Example 20: Region Drilldown using prority regions

<%= geography_division_select(“geography”,”geography”,:drilldown=>”region”,:priority=>”Asia,North America,Europe”) %></p>

Displays all the 7 regions of the world with Asia, North America and Europe in the priority segment

 

 

 

<p>Example 21: Country Drilldown using Priority items

<%= geography_division_select(“geography”,”geography”,:drilldown=>”country”,:priority=>”United States Of America,United Kingdom,India”) %></p>

Displays all the 239 countries of the world with USA, UK and India being in the priority list.

</p>

Is this It or any thing is more pending?

I have tried my level best to implement everything, however there is still formatting options that I need to provide. Currently when a developer selects a country only countries will be listed and so is with regiond and states.

However I have a plans to implement formatting options such that we display a drill down mechanism to allow users to view the dropdown in a much better fashion.

So much for the next version.

Disclaimer

The list of Regions, Countries, States/Provinces/Districts/Atolls/Islands, etc., are based on informatoin collected in the internet.

We are thankful to various sites  especially to Wikipedia.org for having provided the information. All the data provided have been converted into

pure english alphabet format and special characters are converted to its nearest english alphabet. The authors have tried their level best to provide

adequate and correct information based on the analysis and takes no responsiibility if so ever if any information is incorrect or is in form that

offend any users. The authors acknowledges if any error is brought to notice and shall make necessary changes. Please review the data carefully before you use them.

 

All issues and inappropriate data can be brought into the notice of info@heurionconsulting.com

Licensing?

We follow MIT License. Look out for the MIT-LICENSE file in the plugin folder

Introduction

Bookmark_url_to is the second plugin that I wrote to provide support for ruby on rails programmers to allow them speed up their programming activities. I had gone through 2 more plugins before I decided to write a new one.  I felt there were more work for the developers to understand and co-ordinate in building their applications with plugins. However i still feel the existing plugins are cool… Also I wanted to include multiple options such as showing images or text or both OR show your own text, right at the time of writing the code.

what does Bookmark_url_to  do?

bookmark_url_to provides support for users to connect thier url and titles to 57 social bookmarking sites including digg, technorati, delicious, comments, google, yahoo,etc.,. bookmark_url_to supports bookmarking to Browser Favorites and also if you want to send a particular url to your friend through your mail application. 

The various sites that we support are

Allows users to Bookmark their pages to standard websites

1. BlinkBits (:blinkbits)
2. BlinkList (:blinklist)
3. BlogMarks (:blogmarks)
4. BlogMemes (:blogmemes)
5. BlueDot (:bluedot)
6. Bumpzee (:bumpzee)
7. Co.mments (:comments)
8. Connotea (:connotea)
9. Del.icio.us (:delicious)
10. De.lirio.us (:delirious)
11. Digg (:digg)
12. Diigo (:diigo)
13. DotNetKicks (:dotnetkicks)
14. Dzone (:dzone)
15. Fark (:fark)
16. Facebook (:facebook)
17. Favorites (:favorites) — (Add Favorites in Browser)
18. FeedmeLinks (:feedmelinks)
19. Fleck (:fleck)
20. FriendSite (:friendsite)
21. Furl (:furl)
22. Google (:google)
23. IceRocket(:icerocket)
24. Kaboodle (:kaboodle)
25. LinkAGoGo (:linkagogo)
26. Ma.gnolia (:magnolia)
27. MailTo (:mailto) — open e-mail editor(outlook)
28. Maple (:maple)
29. MisterWong :misterwong)
30. MySpace (:myspace)
31. Netscape (:netscape)
32. NetVouz (:netvouz)
33. Newsvine (:newsvine)
34. PlugIm (:plugim)
35. PopCurrent (:popcurrent)
36. Propeller (:propeller)
37. RawSugar (:rawsugar)
38. Reddit (:reddit)
39. Rojo (:rojo)
40. ShoutWire (:shoutwire)
41. Simpy (:simpy)
42. Sk*rt (:skirt)
43. SlashDot (:slashdot)
44. SphereIt (:sphere)
45. Spurl (:spurl)
46. Squidoo (:squidoo)
47. StumbleUpon (:stumbleupon)
48. Taggly (:taggly)
49. TailRank (:tailrank)
50. Technorati (:technorati)
51. ThisNext (:thisnext)
52. Twitter (:twitter)
53. WebRide (:webride)
54. Wists (:wists)
55. Vigillar (:vigillar)
56. Yahoo (:yahoo)
57. WindowsLive (:live)

 

Who are the authors of bookmark_url_to?

Satish Kota. He is the founder and chief technical architect of Heurion Consulting Pvt Ltd. A small RoR shop based in Bangalore, India. We have been providing exciting RoR services. Visit our website www.heurionconsulting.com

Where is bookmark_url_to plugin available?

It is available in git. The public clone to this git is git://github.com/heurionconsulting/bookmark_url_to.git

 

 

How to use bookmark_url_to ?

Using bookmark_url_to is very simple and easy. There are no models or controllers or database tables created. All you have to do is run the installation and call one method in your view as per your requirement. You might have to include a stylesheet that gets created in your stylesheets folder. Follow the below code

Post Installation Activity 

 * Once installation is doneall you have to do is to call the below 2 lines of code in your Views i.e. where you want to show the url links<%= stylesheet_link_tag “bookmark_url_to” %>

<%= apply_bookmark_url_to(url,title,sites,options) %>

where

url -> URL of that page which you want to bookmark e.g. http://localhost:3000/product/show/1 or http://localhost:3000/product/my_product_item

title -> title in which the url has to be bookmarked e.g. my_product_item

sites -> Collection of all the sites to which you want to associate your url and title to.

conditions-> [:all] — Associate this to allow all the 58 links to be added to the list

[:google, :facebook, :myspace,....] — Show only google, facebook, myspace elements in the list

options -> There are 2 options that could be added to execute this plugin

:text –> In this Option you can give the text that you want to show to the viewers before you

see the site links (generally it is “share”). By default this options is set to empty

:visibility_type –> This option is used to control the visibility type. There are only 3 types listed

“image” –> Show only image of the sites

“text” –> Show only the site names

“both” –> Show both image and text

:site_text –> This option is to replace any of the standard text that you want to show to the user instead of the standard text.

If you use this option then the text will be replaced in the text as visible to the user and in the alt section

of the image element.

Styling the application

When ever you install the plugin and run the server after installation, some of the files get loaded into the system. One of these are

bookmark_url_to.css which has necessary divs and classes can be styled. The styled elements are

#bookmark_url_to{..put your styling code here } this is the outer div

which you can style to set width

.bookmark_url_to_element{…put your styling code here} this is the div for each

of the div where each type of site is selected.

.bookmark_url_to_text{…put your styling code here} this div is for the div where you want to add you text.

Examples?

 

 

 1. example method call for all sites would look like<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:all],{:text=>”share : “,:visibility_type=>”text”}) %>

2. example method call for all sites to show both image and text

<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:all],{:text=>”share : “,:visibility_type=>”both”}) %>

3. example method call for a few set of sites to show only image

<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:google,:facebook,:myspace, :favorites,:digg,:technorati],{:text=>”share : “,:visibility_type=>”image”}) %>

4. example method call for all sites to show text in required format

<%= apply_bookmark_url_to(“http://localhost:3000/”,”TEST”,[:all],{:text=>”share : “,:visibility_type=>”both”,:site_text=>{:delicious=>”del.icio.us”,:delirious=>”de.lirio.us”,:comments=>”co.mments”}}) %>

 

Licensing?

We follow MIT License. Look out for the MIT-LICENSE file in the plugin folder

Introduction

When I was implementing some projects for our clients, I came across multiple activities where we used quite a lot of acts_as_XXX plugins… some of  them well known and vastly used were acts_as_commentable, acts_as_taggable, acts_as_rateable…etc., However when a new requirement came in from some no where where we wanted to implement a system where the client wanted to implement fans for all the users and also for games. Then the idea struck as to why not make a plugin to allow others to use this feature

what does ACTS_AS_FANNABLE  do?

acts_as_fannable is a simple plugin written to help Ruby on Rails Models to associate fans to it..e.g.. People can have fans, Books can have fans, Items can have fans, sports can have fans etc.,. This project helps ruby on rails programmers with a system to implement fannable situation.

Who are the authors of acts_as_fannable?

Satish Kota. He is the founder and chief technical architect of Heurion Consulting Pvt Ltd. A small RoR shop based in Bangalore, India. We have been providing exciting RoR services. Visit our website www.heurionconsulting.com

Where is acts_as_fannable plugin available?

It is available in git. The public clone to this git is git://github.com/heurionconsulting/acts_as_fannable.git 

 

How to use acts_as_fannable ?

Acts_as_fannable is much similar to Juxie’s acts_as_commentable. We have picked the idea from there. All you have to do is follow the Read me file. However to the benefit of users. The below code is what you can use from.

I  Creating the migration File

Creating a migration file is very necessary because we need a database to create and store the fans for the models. we suggest you follow the below steps to do the activity.

a. creating migration file

./script/generate migration acts_as_fannable

The code creates a file in db/migrate/20090130102017_acts_as_fannable.rb where you need to enter the details of the table you need to create

b. add content to the migration file.

Just copy the below code into your migration file. This creates the necessary table that is required to use the acts_as_fannable plugin.

 def self.up
    create_table “fans”, :force => true do |t|
      t.column “fannable_id”, :integer, :default => 0, :null => false
      t.column “fannable_type”, :string, :default => “”, :null => false
      t.column “user_id”, :integer, :default => 0, :null => false
      t.time_stamps
    end
 
    add_index “fans”, ["user_id"], :name => “fk_fans_user”
  end

  def self.down
    drop_table :fans
  end

c. run the rake command

rake db:migrate

This command shall create the fans table within your database. Ensure you already have created a database and updated your database.yml file.

II Usage of acts_as_fannable

a. Making a model acts_as_fannable.

Open your Model file e.g. User, Game,  Sport, Personality, Singer, Musician, Teacher, Student, etc.,

Add the acts_as_fannable element to it as shown below.

class Model < ActiveRecord::Base
   acts_as_fannable
end

This makes your model acts as fannable and now all the other users can become a fan of this model.

b. adding a fan to the model instance

In your controller, where you want to pick up the user to be a fan of the model, you can run an instance of the model, setup the user as fan and add them to the list. Note: you might have to get your user to login before they want to add themselves as fan. So your controller could look as

 model = Model.new
fan = Fan.new
fan.user_id = user.id (or self.current_user.id if acts_as_authenticated or restful authentication being used)
model.fans << fan
or
model.add_fan(fan)
Thats it you are ready to use the plugin.

 

Licensing?

We follow MIT License. Look out for the MIT-LICENSE file in the plugin folder

 

 

Active Scaffold is a great tool to provide a perfect AJAX based Scaffolding system for Rails Lovers. The flexibility that is build is in comparable. However as with any system not everything is possible, but yes for items where some of the activities is not possible active scaffold gives the actions to you to handle.

 

Some of them are as follows.

 

  1. You have a requirement to do a bulk upload of all the products that you have in your excel and do not want to create them one by one
  2. You have a requirement to run a calculation such as tax activity that you want to do only for each product after it is created. This calculation might not be part of the basic database fields that you have in the active scaffolds.

 

So for either of the above requirement you do not have a field in the active scaffold  / t able that is declared and they are not the normal active scaffold operations. This is something new. How do I handle it?

The solution is by using Active Scaffold Links (also called as action_links ) which helps you to connect to any action that you declare in your controller.

 

There are two types of active scaffold links, one is the table type and another is the record type. The Table type is best suited when you wan to use them for bulk upload activity i.e. that is one time activity and is not dependent on any particular object. And the Record type is used when you want to involve information of one particular object (product in this case)

 

How do we declare these elements. Within your active scaffold elements you have to declare the following items

 

config.action_links.add “bulk_upload”,:label=>“Bulk Upload”,:type=>:table

 

config.action_links.add “showproductcalculation”,:label=>“Product Calculation”,:type=>:record

 

 

The first link is of Table type. This link when added to active scaffold adds it just next to the Create / Search buttons. Which says that this information is irrespective of any particular object. However the second link being a record type is added just next to the edit / delete / show links for a particular product.

 

Looking at a sample active scaffold of this type we have the controller written as follows

 

active_scaffold :product do |config|

  config.label = “Product” # Display page name

  config.columns = [:name, :description, :product_image]

  config.action_links.add “bulk_upload”,:label=>“Bulk Upload”,:type=>:table

  config.action_links.add “showproductcalculation”,:label=>“Product Calculation”,:type=>:record

end

 

def bulk_upload

  # do all your Bulk Uploading stuff which is launches the bulk_upload.rhtml file

  # if available in the views/products folder

end

 

def showproductcalculation

  #do all your product calculation that you want to do for a particular product

   # The product id is available as params[:id]

   product = Product.find_by_id(params[:id])

   @displayproductinfo  = product.value *25/123;

end

 

Well that means bulk upload displays the bulk_upload action and subsequent bulk_upload.rhtml and the showproductcalculation is called.

 

The difference in the table type and record type is that in record type you have the pointer to the selected product through params[:id] which is not available in case of table type.

 

That’s what it is… using links in active scaffold, If you want to make this part ajaxified, you can always put your ajax code and make them work.

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

In all our blogs we have all spoken about integrating some thing or the other… and also we have spoke about setting up text_areas, text_fields, etc., as part of our string database fields. However if you wanted some information which had to have rich text then, there is no support from the Active Scaffold end.

 

Whenever a rich text creation comes into mind, the first thing that we think about using a rich text editor (WYSIWYG) Editor which you would like to integrate with your text box to make it a rich text and provide all the styling features.

 

From experience we know that the Tiny MCE is the best and well known Rich Text Editor which is used in the internet world to implement Rich text…however tiny mce fails when it comes to using it within active scaffold… The reason is that active scaffold is a complete ajax application and for some reason it has failed to work. We also tried using the tinymce patch to make it work, but unfortunately it was not possible.

 

To our rescue came in the FCK Editor Plugin. By using this plugin we can ensure active scaffold textfields can be made rich text and get all the features that we get in tiny mce if not more. Also FCK Editor seems to be a much robust and better WYSIWYG editor which is being used by the Rails world.

 

Assuming FCK Editor Plugin is installed in your application. All you need is to change the details in the helper file. Since FCK Editor is a UI feature, you don’t have to do any change in the controller. In our example we have taken up the description field of the category class (Refer to our previous active scaffold posts) to which we need to provide rich text information.

 

In Category_Helper.rb we need to add the following code

 

#description field is shown in FCK editor format

def description_form_column(record, input_name)

 fckeditor_textarea( :record, :description, :toolbarSet => ‘Simple’, :name=> input_name, :width => “800px”, :height => “200px” )

end

 

#description text is displayed in rich format

def description_column(record)

 sanitize(record.description)

end

 

 

Thats it, You should be able to view the FCK editor in your active scaffold. However there is one issue, FCKEditor shall replace your description field and add its own description text area which provides the rich text information. Hence forth whatever you type in the rich text box is not actually available as the Value field of the basic description text field (which has been overwritten by FCKEditor). So while storing the contents of the description field to the database, the contents are not available to be stored. In order to solve this problem we need to add a small glitch into our code.

 

For this copy the “_create_form.rhtml” & “_update_form.rhtml” from ..\vendor\plugins\active_scaffold\frontends\default\views to Views/Category folder and edit them as follows

 

In  _create_form.rhtml you need to replace the submit button to have FCKEditor information as below

 

Instead of <%= submit_tag as_(‘Create’), :class => “submit” %>

 

we add following code

<input type=“submit” value=“Create” class=“submit”

onClick=“var oEditor = FCKeditorAPI.GetInstance(‘record_<%=@record.id%>_<%=’description’%>_editor’);

document.getElementById(‘record_<%=@record.id%>_<%=’description’%>_editor’).value = oEditor.GetXHTML();” />

 

The above code provides the mechanism to get the HTML content of the FCKEditor Record and place them in the value field as when we use the FCKEditor above the normal description text_field, it over rides the text field and placed its own rich text field. Since FCKEditor now transfers the content to the value field, this information will be available when the create / update actions of the controller is run.

 

You need to do the same in the _update_form.rhtml to get the fckeditor html content into the value field.

 

Once the glitch is added, your FCKEditor should work fine with active scaffold.

 

 

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

Though Active Scaffold is a plugin which is used for ajax activities, for some cases where we want to upload images / files as part of our object, active scaffold fails as the basic file field will not work correctly with active scaffold. The reason is active scaffold is an ajax based system and file field is a non ajax based system…. However to the rescue comes in the File Column Plugin in Active Scaffold. There is a hook available that can be implemented to ensure file column works perfectly well with the active scaffold. The details are as follows

 

Requirements

  1. Active Scaffold Plugin is installed
  2. File Column Plugin is installed

 

Continuing from my previous active scaffold articles, I derive the problem of the products to show a image as part of the product activities. So the active scaffold I re-write would be as below

 

active_scaffold :product do |config|

    config.label = “Product Page”

    config.columns = [:product_name, :product_description, :product_image]

    config.create.multipart = true

    config.update.multipart = true

    config.columns[:product_image].label = “Product Image”

end

 

what I do here is just add a field :product_image which stores the file path of the image that is updated. However just adding the product image shall not do the job, like with other fields we have to override the product_image column and form_column methods in the helper methods to use file column plugin field.

 

So in our Product_Helper.rb we add  the below code

 

The below code is called by the create and edit actions which shows the user a file column filed to allow upload of the image for a particular row.

 

def product_image_form_column(record, input_name)

 file_column_field ‘record’, :product_image

end

 

 

The below code is called during the list and show actions to display the image that is associated to the product.

 

def product_image_column(record)

  image_tag url_for_file_column(record, product_image) if record.product_image

end

 

Hurray, my work is done the active scaffold now understands the file column. However there is still one question how does the active scaffold know that the product image is a type of file column…. Well all we need to do is one small modification in the Product.rb  (model file)

 

file_column :product_image

 

Finally done your active scaffold has been integrated with the File column. Which means there is a non ajax activity (file upload) with in an ajax activity (active scaffold).

 

That’s it enjoy coding….

 

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

 

 

 

 

 

 

 

 

 

You have a problem that is you see a button Search next to Create and you dont know how to make use of it…Integrating Search in Active Scaffold is very easy.

 

In controller we need to write the following code to make it work:

Considering the category we have

 

active_scaffold :category do |config|

  config.label = “Category” # Display page name

  config.columns = [:name, :rank, :description, :products]    

  config.columns[:name].label = “Some Name”

  update.columns.exclude :rank # exclude rank column during edit

  # Search the list by name

  config.columns[:name].search_sql = “name”    

  config.search.columns << :name

  # Search the list by product name

  config.columns[:products].search_sql = “products.name”    

  config.search.columns << :products

 

end

 

What active scaffold does is that when ever you use the search with a keyword, it will search the category name and the product name for a particular keyword and returns the resulting categories

 

Simple isn’t it….

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

 

Welcome to my yet another article on Active Scaffold. This time I am going to explain how to relate 2 tables within each other.

 

Let us assume you have a table category ( same name from my first article on active scaffold ) to which you want to associate products. So basically we have 2 Models Category (table name as categories) and Product (table name as products) which have a relationship bound as category :has_many => products and product :belongs_to => category. So basically a product can be associated to only one category.

 

There are two ways of building this

 

  1. Create a Category and with in it create a product
  2. Create a product and have a Dropdown for category to select while create / edit

 

Though it is very simple to do the latter i.e. creating a product and having a dropdown for category to select while create / edit, but the Former is much difficult. However in Active Scaffold it is much simpler. All you have to do is to associate the relationships and provide a relationship linking.

 

Coming back to my category controller (refer to my first article on active_scaffold), I now re-write it as

 

active_scaffold :category do |config|

  config.label = “Category” # Display page name

  config.columns = [:name, :rank, :description, :products]

  config.columns[:name].label = “Some Name” # customize column name

  update.columns.exclude :rank # exclude rank column during edit

  list.columns.exclude :description #exclude description column in list

  #this is a extra link which is applicable for every row if type record and if type is table then it is for all records

  config.nested.add_link “Add Products”, [:products]

end

 

All this says that to the existing system is that add a link along with create edit delete by name as Add Products and when it is clicked show all the products (as active scaffold) associated to that particular category.

 

Nested is a way of adding a table within a table and is used in case of displaying parent-child relationship. In this case the Category has a nested relationship with products table.

 

This doesnot finish it all. We still need to code what needs to happen when you click on the Add Products link. For that you need to generate a product controller and have a product model and table generated. In this case let us assume that the product table have the following fields

 

  • Product Name
  • Product Description
  • Category ID

 

Though here what we actually need is the product name and description, we need category_id field to establish a contact with it’s parent category table.

 

active_scaffold :product do |config|

  config.label = “Product Page” # Display page name

  # Category_id not needed by default it will take while adding

  config.columns = [:product_name, :product_description]

  config.columns[:product_name].label = “Product Name”

  list.columns.exclude :product_description

end

 

That’s it, now run your Now in your page you can

 

  1. Add / Edit / Delete Categories as you did in my first article
  2. Click on the Add Products and you see a nested table displayed where you can add / edit / delete products which are associated to that particular category.

 

Cool isn’t it? Look out for more information on active scaffold.

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

Acivescaffold is a plugin which makes the life easier for many programmers and provides Ajaxified implementation. Active scaffold can also be called as the next generation component which replace ajax_scaffold plugin. It comes as a plugin which can be downloaded and installed.

 

To install active_scaffold plugin all you just need to do is

 

> ./script/plugin install active_scaffold

 

Now that we have installed the plugin, lets try to do something with it. The Goal is to create a CRUD for a model / table name Category / categories where we would like to create / edit / delete all the categories that can be used in the application.

 

Lets assume the table has the following fields

  • Name
  • Rank
  • Description
  • Disable status

 

So what do we do now?

 

Create a controller called categories ( name doesn’t matter) as

 

> ./script/generate controller category

 

This script generates a category_controller.rb, category_helper.rb and categories folder within /app/views. The views are not of importance as we don’t need them for this example.

 

Now in controller we need to write the following code:

 

active_scaffold :category do |config|

  config.label = “Category” # Display page name

  config.columns = [:name, :rank, :description, :disabled] # all fields are taken

  config.columns[:name].label = “Some Name” # customize column name

  update.columns.exclude :rank # exclude rank column during edit

  list.columns.exclude :description #exclude description column in list

end

 

 

What the above section does is

 

  1. Tells active_scaffold that the table name is categories (i.e. plural of category)
  2. Shows the Label in the top bar as Category
  3. Identifies the fields name, rank, description, disabled that can be controlled through active_scaffold
  4. Where ever name is used, it is replaced by Some Name i.e. in the list, create and update pages / forms
  5. Eliminate rank to be updated while edit is in progress
  6. Hide description in the List ( show only in Show page)

 

Once this is done, most of your work is actually complete. You run the server and go to the categories controller i.e. http://localhost:3000/category and you should be able to start using it.

 

However the items that you use to create and edit is actually coming in from the plugin and always the information is text field for fields with varchar and text declaration and dropdown for boolean fields (the drop down always contains True or False)

 

However if I want to override these implementation all I need to do is do some minimal modifications in the helper file.

 

In Category_helper.rb for each field(column) there are 2 methods that is declared. One as XXX_form_column and XXX_column.

 

XXX_form_column is always used when you want to over-ride the way you want to display the field information in the forms that is used by the create / edit process and XXX_column is always used when you want to over-ride the way you want to display  need to write the following code to display the field in case of list and show. Just as an example follow below

 

# Textarea to enter the description

def description_form_column(record,input_name)

  textarea :record, :name, :name=> input_name

end 

 

# Dropdown to select rank

def rank_form_column(record,input_name)

  select(:record,:pricing,[1,2,3,4,5,6,7,8,9,10],:name=> input_name)

end

 

# Label to display rank

def rank_column(record)

  output = “”

  record.rank.each do

      output += “*”

  end

  output

end  

 

In the above example you see that we have modified only the description and the rank fields. That means the Name and Disabled fields shall still use the basic active_scaffold’s implementation. Also if you see that we have overridden the description_form_column only and not description_column as we wish only to handle the case of description to use a text-area while creating / editing a category.

 

However incase of Rank, we have overridden both type as we feel that user needs to have a dropdown where he select the rank and also while showing to the user, instead of showing the number we want to override by showing the number of stars to it.

 

That’s it and code will work fine. No rhtml code has been used here. Stop by and view my other articles on active_scaffold… enjoy coding !!!

 

About Author: Ganesh Mohan is a Senior Developer working for Heurion Consulting Pvt Ltd, Bangalore, India, Providing solutions in Ruby on Rails and Microsoft Technologies. Though he has quite acquainted with both the technologies and always in a position to suggest which platform / technology is good enough for what kind of application to be developed. Ganesh has a computer science degree from Visvesvaraya Technical University, Karnataka

 

 

About Heurion Consulting: Heurion Consulting is an organization based in Stoke-on-Trent, UK and Bangalore, India providing solutions using Ruby on Rails technologies. We help organizations build websites to allow them sell their products, or help a group / team  / individual to recognize a pain area or build an idea that they want to evolve. Heurion Consulting have supported various Entrepreneurs realizing their dreams. For more details contact info@heurionconsulting.com and our website is www.heurionconsulting.com

 

 

 

 

 

Next Page »

Follow

Get every new post delivered to your Inbox.