rails basics

Posted on April 21, 2008. Filed under: Uncategorized |

render(:controller=>’say’ ,:action=>’hello’)

render(:partial => ‘form’)

redirect(:controller=>’say’ :action=>’hello’)

link_to(’mylink’,:controller= >’say’,:action=>’hello’,:id=>1)

params.inspect

logger.warn,logger.error,logger.info,logger.fatal

(ActionView only) debug(params)

( FormHelpers only)

<input type =’text’ name=album[title]/> can be written as

<%= form_tag(:action=>’create’) do %>

<%= text_field(:album, :title) %>

<%= datetime_select(:album, :release_date) %>

<%= submit_tag(”name of button”) %>

<%= end %>

form_tag

form

 

error_messages_for(:album) —> debug(album.errors)

validates_presence_of :artist

before_filter(controller) :method :o nly/:except =>[]

after_filter(controller) :method :o nly

Model inherits from ActiveRecord::Base which has methods like find,find_by_id,find_by_sql,save,update,destroy

Controller is inherited from ApplicationController

stylesheet_link_tag

layout(controller)

render(:layout=>false/’standard’) / render_without_layout

before_create(ActiveRecord::Base)

after_create(ActiveRecord::Base)

flash[:notice] = ’successful created’

Database table end with s…Albums,Artists,

But the model is singular and the controller is

Sql

1)find(:all, –> :first,:last,1….

(where clause) :conditions= >["release_date <= ?","YYYY-MM-DD HH:MM:SS"] –> sql inject attack…

:o rder=>’release_date ASC’

:limit => 10 , :o ffset => 5

 

{
:primary_key => “int(11) DEFAULT NULL auto_increment PRIMARY KEY”,
:string => { :name => “varchar”, :limit => 255 },
:text => { :name => “text” },
:integer => { :name => “int”, :limit => 11 },
:float => { :name => “float” },
:decimal => { :name => “decimal” },
:datetime => { :name => “datetime” },
:timestamp => { :name => “datetime” },
:time => { :name => “time” },
:date => { :name => “date” },
:binary => { :name => “blob” },
:boolean => { :name => “tinyint”, :limit => 1 }
}

2)create a new model and call .save(will return true / false)

3)destroy : instance of the model.destroy

4)update_attributes : instance of the model.update(params–>hash)

PARAMS

is a hash.so to get the params say params[:key] eg params[:id]

Make a Comment

Make A Comment: ( None so far )

blockquote and a tags work here.

  •  

    April 2008
    M T W T F S S
    « Mar   Jun »
     123456
    78910111213
    14151617181920
    21222324252627
    282930  
  • My Fav

Liked it here?
Why not try sites on the blogroll...