Rails vs Merb example codes with some refactoring

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.

Iklan

Satu Tanggapan

  1. I love your site! 🙂

    _____________________
    Experiencing a slow PC recently? Fix it now!

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

%d blogger menyukai ini: