Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Yacobus Reinhart <yacobus.reinhart-Re5JQEeQqe8AvxtiuMwx3w <at> public.gmane.org>
Subject: Re: Tanya tentang Respond_with, Rails 3
Newsgroups: gmane.comp.lang.ruby.region.indonesia
Date: Tuesday 31st January 2012 15:52:34 UTC (over 4 years ago)
coba pake method saya, biasanya saya taro di application_controller.rb atau
saya buat module sendiri

respond_to :html, :xml, :json, :amf, :fxml

def api_responds(*args, &block)
    respond_with(*args) do |format|
       format.any(*navigational_formats, &block)
    end
 end

def respond_after_save(is_success, object, actions)
      if is_success
        set_flash_message :notice, params[:action].to_sym  if
is_navigational_format?
        uri = actions[:success_to].present? ?
send("#{actions[:success_to]}_path")  :
url_for(send("edit_#{params[:controller].singularize}_path",
object))
        api_responds(object){ redirect_to uri, :layout => request.xhr?}
      else
        api_responds(object.errors.full_messages){ render :action =>
actions[:failed_to], :layout => request.xhr? }
      end
 end

# How To Use:
# If request ajax maka tidak pakai layout
# def update
#
respond_after_save(@client.update_attributes(params[:client]),@client,{:failed_to
=> "edit"})
#  end
#
# def index
#    api_responds(@clients)
# end

Jack


On Tue, Jan 31, 2012 at 2:10 PM, Adhitia Hidayat
wrote:

> @nugroho Betul saya juga setuju.... kalo kayanya memang respond_with
belum
> bisa handle
>
> @pascal : masih sama scal,,,
>
> lihat di konsole nya masih render ke application.html.erb, walau udah
pake
> exact Path
>
> *Rendered brands/_form.html.erb (15.0ms)
> Rendered brands/new.html.erb within layouts/application (17.0ms)*
>
>
> On Tue, Jan 31, 2012 at 2:03 PM, Nugroho Herucahyono
 wrote:
>
> > **
> >
> >
> > Imho, sepertinya lebih simple kalau nggak pakai respond_with
> >
> >
> > def create
> > @brand = Brand.new(params[:brand])
> > if @brand.save
> > redirect_to @brand, :notice => "Brand has been added"
> >
> > else
> > flash.now[:alert]="Failed to create Brand"
> > render "new", :layout => "no_header"
> > end
> > end
> >
> >
> > On Tue, Jan 31, 2012 at 1:44 PM, Adhitia Hidayat
> > wrote:
> >
> > > udah di coba, tapi hasil nya tetap sama
> > >
> > > kalo begini bisa
> > >
> > > *respond_with @brand do |format|
> >
> > > format.html { render(:action => "new", :layout => "no_header") }
> > > end*
> >
> > >
> > > tapi kalau di set seperti itu, kalau save nya berhasil, yang di
lakukan
> > > tetap render :action => new .. bukan redirect
> > >
> > > On Tue, Jan 31, 2012 at 12:59 PM, Nugroho Herucahyono

> > > wrote:
> > >
> > > > **
> >
> > > >
> > > >
> > > > bisa dicoba begini?
> > > >
> > > >
> > > > def create
> > > > @brand = Brand.new(params[:brand])
> > > > if @brand.save
> > > > flash[:notice] = "Brand has been added"
> > > > else
> > > > flash.now[:alert]="Failed to create Brand"
> > > > end
> > > > respond_with @brand do |format|
> > > > format.html { render(:layout => "no_header") }
> > > > end
> > > > end
> > > >
> > > >
> > > > [Non-text portions of this message have been removed]
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Warm Regards
> > > ~ Adhitia Hidayat Saputra ~
> > > Ruby On Rails Developer
> > >
> > >
> > > [Non-text portions of this message have been removed]
> > >
> > >
> > >
> > > ------------------------------------
> >
> > >
> > > ID-Ruby
> > > Berdiskusi dan belajar bersama Bahasa Pemrograman Ruby, termasuk
segala
> > > varian Ruby (JRuby, Rubinius, IronRuby, XRuby), dan program yang
dibuat
> > > dengan Ruby (Ruby on Rails, JRuby on Rails, Merb)
> > >
> > > http://rubyurl.com/Q8DD
> > > http://news.gmane.org/gmane.comp.lang.ruby.region.indonesia
> >
> > >
> > >
> > >
> > >
> > >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
>
>
>
> --
>         Warm Regards
> ~ Adhitia Hidayat Saputra ~
>  Ruby On Rails Developer
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> ID-Ruby
> Berdiskusi dan belajar bersama Bahasa Pemrograman Ruby, termasuk segala
> varian Ruby (JRuby, Rubinius, IronRuby, XRuby), dan program yang dibuat
> dengan Ruby (Ruby on Rails, JRuby on Rails, Merb)
>
>    http://rubyurl.com/Q8DD
>    http://news.gmane.org/gmane.comp.lang.ruby.region.indonesia
>
>
>
>
>


-- 
*"To accomplish great things, we must not only act, but also dream; not
only plan, but also believe."* *~ Anatole France*


[Non-text portions of this message have been removed]



------------------------------------

ID-Ruby
Berdiskusi dan belajar bersama Bahasa Pemrograman Ruby, termasuk segala
varian Ruby (JRuby, Rubinius, IronRuby, XRuby), dan program yang dibuat
dengan Ruby (Ruby on Rails, JRuby on Rails, Merb)

<*> Follow Ruby Indonesia on Twitter
    http://twitter.com/rubyindonesia

<*> Kunjungi Situs Resmi Ruby Indonesia
    http://www.ruby-lang.org/id/

<*> Join Ruby Indonesia on Facebook
    http://rubyurl.com/QV48

<*> Join Ruby Indonesia on LinkedIn
    http://rubyurl.com/eh0i

<*> Kunjungi *arsip milis* id-ruby di
    http://groups.yahoo.com/group/id-ruby/messages
    http:[email protected]e.org/
    http://rubyurl.com/Q8DD
    http://news.gmane.org/gmane.comp.lang.ruby.region.indonesia

<*> Baca peraturan id-ruby sebelum posting
    http://rubyurl.com/gay1
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/id-ruby/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/id-ruby/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
CD: 20ms