Rails 1.2 Depricated

written by Dariush 1 day ago

Thanks to Rubyonrails.org

RubyonRails Deprecated

Also checkout

Additional pattern

Action Pack:

components use partials and helper methods instead @params, @session, @flash, @request, @cookies, @headers, @response

Use the params, session, flash, etc methods instead of working with the instance variables directly. url_for(:symbol, args), redirect_to(:symbol, *args)

use named routes instead

render_text, render_template, etc. use e.g. render :text => ..., render :template => ..., etc.

redirect_to_path, redirect_to_url. Use redirect_to.

post_format, formatted_post?, xml_post?, yaml_post? Use respond_to or request.format.

start_form_tag and end_form_tag Use form_tag with a block.

update_element_function use RJS

link_to_image, link_image_to helper methods use link_to(image_tag(..), url)

human_size helper alias use number_to_human_size helper method

Active Record:

find_first, find_all Use find :first and find :all. push_with_attributes Use has_many :through for rich many-to-many associations. *association_count Use association.count instead

Railties:

Non-namespaced rake tasks like rake migrate. Use rake db:migrate.

Find_by_sql

written by Dariush about 1 month ago

A question that came up in our recent brain storming dealt with how to run sql within the rails code if AR (active records) has limitation. In my research I found that most of the work should be performed with AR, however there is also the function of find_by_sql

http://ar.rubyonrails.com/classes/ActiveRecord/Base.html#M000345

find_by_sql(sql)

Works like find(:all), but requires a complete SQL string. Examples:

Post.find_by_sql "SELECT p.*, c.author FROM posts p, comments c WHERE p.id = c.post_id" 
Post.find_by_sql ["SELECT * FROM posts WHERE author = ? AND created > ?", author_id, start_date]

Setting up Rails on windows

written by Dariush about 1 month ago

Here are a list of commands to get rails on windows up and running.

First you need to install ruby. You can get it from

Install rails:

gem install rails --include-dependencies

Install mongrel:

gem install mongrel --include-dependencies

Choose mswin32 for your platform if you are presented with options

Start mongel:

mongrel_rails

Update your gem:

gem update

Step-by-Step instructions for running a Subversion under Windows

written by Dariush 4 months ago

Creating a repository

I selected to put the repository in a new folder named SvnRepos the root of my C: drive, so the command I used was:

svnadmin create C:\SvnRepos

Adding your source code the first time

I keep my source code or projects under a folder called work_source. Lets import all the files and the subfolders:

svn import work_source file:///c:/SvnRepos/work -m "initial import"
work_source is folder under c: drive that contains all my other folders and files

Creating a working copy to work on

Now that your code is checked into the repository, you need to create a working copy to use in making your changes. This is done using the svn checkout command. I created my working directory at c:\work_current, so the following command was used:

svn checkout file:///c:/SvnRepos/work work_current

Overwriting specificity in CSS

written by Dariush 5 months ago

To overwrite specificity in your css style sheet you can declare it as follows:

h1 {background: green !important;}

The important above overwrites the specificity in the entire style sheet. It can be a good debugging tool to figure out where else we have a style declared that conflicts with this one.

Make sure not to leave the !important in there in the production mode.

Rails conventions

written by Dariush 5 months ago

Naming Classes and Files

ClassNames are written in UpperCase (where each word start with a capital letter). That is for the class names.
Now file_names are written in small letters with underscore, as you see here like file_names

Views

The folder in the views folder that store the template is viewed after the controller name A template has a one-to-one relationship with the action within a the controller that is mapped to

Layouts

Layouts control the global layout of the application, the stuff that does not change from page to page. partials are pieces of code that act like the good old include function in php.

Controllers

Instance variables in controllers are defined like @variable. These guys can pass their values down to the corresponding view. When creating a controller with the generate command, you need only to specify the controller’s name. ie. script/generate controller Dariush

what I mean is that you don’t need to write DariushController, otherwise you end up with DariushControllerController.

Keep application logic in the controller according to Patrick Lenz’s book “Build your own ruby on rails application”

Helpers

helper files are named after the associated controller. controller name = controllername its helper = controllername_helper

and they reside in the /app/helpers

Remember, Helpers associated with a controller such as the one above, are only available to the views of that particular controller, with one exception. The group of helpers defined in the /app/helpers/application_helper.rb file are available to any view in the entire application.

Migration

To force a table drop in case the table already exists, here is what we can do:

 
def self.up
   create_table :stories, :force => true do |t|
     t.column  :name, :sring
     t.column  :email, :string
   end
end

Note: Migration will create the id automatically. So don’t stick an id in there.

Geokit and zip code Plugin

written by Dariush 5 months ago

Here are a few free rails plugins that allows you to search by zipcode

Zip Code Plugin GeoKit

GeoKit uses Google Maps and Yahoo Maps to get the information while zip code plugin does it all from the local server using a zipcode database.

Rake tutorial

written by Dariush 5 months ago

Here is an awwwwwwwwwwwwsome article on rake that the guys at railsenvy put together. Here it is

great job on the tutorial.

Table of Contents Why make, a retrospective? How did we get Rake? How does Rake work? How do Rake dependencies work? How do I document my Rake tasks? Rake Namespaces How do I write useful Ruby Tasks? How do I write Rake tasks for my Rails application? Can I access my Rails Models inside a Task? Where can I find more examples?

Mephisto Plugins

written by Dariush 5 months ago

Getting ruby mailer up and running

written by Dariush 5 months ago

Trying to run the following command

ruby ./script/generate mailer

gave me a ton of errors with dependencies missing.

Cannot find gem for Rails =1.1.4: Install the missing gem with ‘gem install -v=1.1.4 rails’, or change environment.rb to define RAILSGEMVERSION with your desired version.

So the following command seems to install the ruby mailer.

gem install -v=1.1.4 rails

link: Check out the page for available generators by the community http://wiki.rubyonrails.org/rails/pages/AvailableGenerators

Updating your Ruby on Rails install

written by Dariush 5 months ago

You can always run the following command to update your ruby on rails install.

Here it is, run this from your prompt:

 gem install rails  --include-dependencies

Also once you have updated your rails, you may want to update your individual applications. Lets say you have an application called “my_app”.

Go into the folder “my_app” and run the following command.

So here it is:

 c:\my_app> rails . 

Yes, you see the dot with a space after rails, this is exactly how you run it.

Now, be careful, it will ask you to overwrite some of the files such the yml file (I mean, database.yml). You may not want to overwrite this file, in which case you simply press n to continue. Hope it helps.

There is also the developmental version of rails which is called rails edge. You can try the dev version of rails for any particular application you have to see the changes that are coming down the pipe.

Once inside the folder of your application say (my_app) you issue the following command.

rake freeze_edeg 

by the way the I just found out the rake task freeze_edge has been deprecated, please use the replacement version

rails:freeze:edge

This command will update your my_app application to the latest developmental version of rails and will create a lot of files and folders in the vendor folder. check it out.


To update your gem

gem update

Once you have done an update do the following to verify:

rails -v
gem -v

Ruby command line ./script/about

written by Dariush 5 months ago

Running the ruby about script will give you information about the environment of your ruby app.

From inside of your application folder run: ruby ./script/about

and my out put on my development box is what is shown below:

C:\apache2\htdocs\my_app>ruby ./script/about

 
gem install rails  --include-dependencies
About your application's environment
Ruby version                 1.8.6 (i386-mswin32)
RubyGems version             0.9.4
Rails version                1.2.3
Active Record version        1.15.3
Action Pack version          1.13.3
Action Web Service version   1.2.3
Action Mailer version        1.3.3
Active Support version       1.4.2
Application root             C:/apache2/htdocs/my_app
Environment                  development
Database adapter             mysql

Mephis and ruby on rails

written by Dariush 5 months ago

Finally got the Mephis installed with the theme that you see. There are a lot of articles about how to install Mephis. So although it took me some time to get it up and running, I am happy with the result.

I will try to post everything I learn during the process and basically treat this blog as my own notbook.

Options:

Size

Colors