Forum: Ruby on Rails RESTful actions' context

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0788f26db45fe53107203f227cd75cb6?d=identicon&s=25 Imobach González Sosa (Guest)
on 2007-01-02 15:25
(Received via mailing list)
Hi all,

I've just started a (little) project for my degree and I'm trying to
embrace, love and experiment with the CRUD+RESTful approach. I must say
that it's amazing how simple my controllers look now. I'm pretty
excited with this way of thinking.

However, I've hitting a problem with this approach. I've some models
that I can create/destroy from different points in my application.
Suppose the typical example with Article and Comments. Suppose that I
have two views: one which display and article with all its comments and
another that displays recent comments (no matter what article they
belongs to).

Suppose, moreover, that I can delete comments from those views. In the
first case, when the comment is deleted, the browser must be redirected
to the first view. However, when the comment is deleted from the second
view, the browser must be redirected to the recent comments views.

The problem, with the CRUD+RESTful approach, I only have an action to
delete comments (CommentController#destroy).

What is The Rails Way to achieve that? Using the context plugin[1]
maybe?

Thank you all.

[1] http://rubyforge.org/scm/?group_id=2485
E48d29dc8fedb2878fa518d41cc63d88?d=identicon&s=25 Jan Prill (Guest)
on 2007-01-02 15:51
(Received via mailing list)
Hi

one option might be

def destroy
  ref = request.env["REQUEST_URI"]
  if ref == '/first_view'
    redirect_to :action => 'first_redirect'
  elsif ref == '/second_view'
    redirect_to :action => 'second_redirect'
  end
end

There are many other way. You might for example pass the redirect_target
as
a parameter:

def destroy
  redirect = params[:redirect]
  redirect_to :action => redirect
end

Cheers,
Jan

--
––––––––––––––––––––––––––––––
http://www.inviado.de - Internetseiten für RAe
http://www.xing.com/profile/Jan_Prill
This topic is locked and can not be replied to.