Yacobus Reinhart | 31 Jan 16:52 2012
Picon

Re: Tanya tentang Respond_with, Rails 3

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( <at> client.update_attributes(params[:client]), <at> client,{:failed_to
=> "edit"})
#  end
#
# def index
#    api_responds( <at> clients)
# end

Jack

On Tue, Jan 31, 2012 at 2:10 PM, Adhitia Hidayat
<adhitia.hidayat@...>wrote:

>  <at> nugroho Betul saya juga setuju.... kalo kayanya memang respond_with belum
> bisa handle
>
>  <at> 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 <me@...> wrote:
>
> > **
> >
> >
> > Imho, sepertinya lebih simple kalau nggak pakai respond_with
> >
> >
> > def create
> >  <at> brand = Brand.new(params[:brand])
> > if  <at> brand.save
> > redirect_to  <at> 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
> > <adhitia.hidayat@...>wrote:
> >
> > > udah di coba, tapi hasil nya tetap sama
> > >
> > > kalo begini bisa
> > >
> > > *respond_with  <at> 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 <me@...>
> > > wrote:
> > >
> > > > **
> >
> > > >
> > > >
> > > > bisa dicoba begini?
> > > >
> > > >
> > > > def create
> > > >  <at> brand = Brand.new(params[:brand])
> > > > if  <at> brand.save
> > > > flash[:notice] = "Brand has been added"
> > > > else
> > > > flash.now[:alert]="Failed to create Brand"
> > > > end
> > > > respond_with  <at> 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://www.mail-archive.com/id-ruby-hHKSG33TihhbjbujkaE4pw <at> public.gmane.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:
    id-ruby-digest@... 
    id-ruby-fullfeatured@...

<*> To unsubscribe from this group, send an email to:
    id-ruby-unsubscribe@...

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


Gmane