rails basics
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
nly/:except =>[]
after_filter(controller) :method
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…
rder=>’release_date ASC’
:limit => 10 ,
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]