rails common codes,
class PostsController < ApplicationController
layout “mylayout”
before_filter :find_post
def edit; end
def update
flash[:notice]=’berhasil’ and redirect_to :action => :list and return if @post.update_attributes(params[:post])
flash[:error]=’gagal maning son!’
render :action => :edit, :id => @post.id
end
private
def find_post
@post = Post.find_by_id(params[:id)
redirect_to :action=>:list unless @post
end
end
############
railers: o..railsnya spt itu?
railers: what’s about merb mas aris??
enyong: lah kiye merb spt iki…
class Posts < Application
layout :mylayout
before :find_post
def edit
render
end
def update
if @post.update_attributes(params[:post])
redirect url(:list_post) #use routing, :message => {:notice => ‘berhasil ! berhasil!’}
# return for now will make blank page on merb not like on rails…hm
else
@notice_message = ‘Waduh gagal maning son!’
render :template => ‘post/edit’ #cant use message=>{…etc}
end
end
private
def find_post
@post = Post.get(params[:id])
redirect url(:controller => :posts, :action => :list)
#cant use return, still confuse it seems a bug?? <= 0.9.9
end
end
that’s all!
hehehe so gaya gitu lho…
ya iyalah….masa sih ya iya […]
*own self note.
I love your site! 🙂
_____________________
Experiencing a slow PC recently? Fix it now!