Posts

Delete and reset database in rails 3

Suppose I have a Ruby on Rails database . I want to delete everything and rebuild the database. Please follow the following steps: rake db:drop rake db:create rake db:migrate  To reset and reload your current schema with all. Just follow rake db:reset rake db:migrate

Rmagic installation problem in rails 3

How to install ImageMagick  In Rails 3 Before installing r magic please installed the required library in your system. please follow the Steps. sudo apt-get install imagemagic sudo apt-get install libmagickcore-dev sudo apt-get install l ibmagickwand-dev After successful installation of the above 3 libraries now run gem install 'rmagick' Now rmagic will install successfully. :)

How to write stored procedure in rails 3

Writing Stored procedure in rails 3 Now using Mysql2 gem writing stored procedure is pretty much easy. Just we need to follow the below steps to write  stored procedure in ORM. 1) Connect the database. client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "XXX", :password => "XYZ", :flags => Mysql2::Client::MULTI_STATEMENTS ) This extra flag option is most important and multiple result sets is normally used when calling stored procedures that return more than one result set. 2) Fetch the data. result  = client.query( 'CALL sp_test'); It will return the Result set. Now result contains first result set and to fetch the Next result set we need to follow the next step While (client.next_result)    result = client.store_result  #To get the next result set end

Rails 3 ActionDispatch::Cookies::CookieOverflow

ActionDispatch :: Cookies :: CookieOverflow ( ActionDispatch :: Cookies :: CookieOverflow ): Problem in rails 3 devise. The problem is with session["devise.facebook_data"] = env["omniauth.auth"] . Twitter's response contains an extra section that is very large and does not fit in the session. One option is to store env["omniauth.auth"].except("extra") in the session instead. This is issue arises where we are storing more than 4K of session data.

rails questions

1) Polymorphic association http://robots.thoughtbot.com/post/159809241/whats-the-deal-with-rails-polymorphic-associations What’s the deal with Rails’ polymorphic associations? The latest big ActiveRecord feature to Rails has been polymorphic associations. Not very clear at first, I found out they’re easier to understand with a couple examples. A common one: class Person < ActiveRecord::Base has_one : address , : as => : addressable end class Company < ActiveRecord::Base has_one : address , : as => : addressable end class Address < ActiveRecord::Base belongs_to : addressable , : polymorphic => true end This basically allows the address class to  belongs_to  any model. Which is nice, the alternative would be to say: class Address < ActiveRecord::Base belongs_to : person belongs_to : company end Then you’d have all these foreign keys in your addresses table but you only would ever have a value for one of them beca