Here is how my restful new action look like:
  def new
    @foo = @widget.build(params[:foo])
    raise NoPost unless request.post?
    @foo.save!
    respond_to do |type|
      type.html { redirect_to foo_url }
      type.js { render :action => :create }
    end
  rescue NoPost
    respond_to do |type|
      type.html { render :action => :new }
      type.js { render :partial => ''form'' }
    end
  rescue ActiveRecord::RecordInvalid
    respond_to do |type|
      type.html { render :action => :new }
      type.js { render :action => :create }
    end
  end
  alias :create :new
Any ideas how to DRY it?
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
rescue NoPost, ActiveRecord::RecordInvalid ? On 10/27/06, W S <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Here is how my restful new action look like: > > def new > @foo = @widget.build(params[:foo]) > raise NoPost unless request.post? > @foo.save! > respond_to do |type| > type.html { redirect_to foo_url } > type.js { render :action => :create } > end > rescue NoPost > respond_to do |type| > type.html { render :action => :new } > type.js { render :partial => ''form'' } > end > rescue ActiveRecord::RecordInvalid > respond_to do |type| > type.html { render :action => :new } > type.js { render :action => :create } > end > end > alias :create :new > > Any ideas how to DRY it? > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Vishnu Gopal wrote:> rescue NoPost, ActiveRecord::RecordInvalid ?But those 2 rescues are different -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Ah sorry, didn''t notice. There''s not much to DRY tho in that
case. Try this:
rescue NoPost, ActiveRecord::RecordInvalid
[..]
 type.js { render :action => ($!.is_a? NoPost) ?  :new : :create }
Just typing this out, but some variation of that will work.
Vish
On 10/30/06, W S
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Vishnu Gopal wrote:
> > rescue NoPost, ActiveRecord::RecordInvalid ?
>
>
> But those 2 rescues are different
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---