SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Syria
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Ajax with layout templates

    Hello,
    Here is the situation:

    I have a List action that lists items for me (scaffold generated), now I need to the destroy method to be ajaxed, I wrote the following:

    Code:
    <%=link_to_remote ('Destroy',
                                :update => "main", 
                                :url => {:action => 'destroy', :id => @category},
                                :confirm => 'Are you sure?',
                                :post => true,
                                :loading => "document.getElementById('loading').style.display='inline'",
                                :loaded => "document.getElementById('loading').style.display='none'")%>
    OK, everything's going fine except that destroy method must -of course- redirect the page to the list action:

    Code:
    def destroy
        Category.find(params[:id]).destroy
        redirect_to :action => 'list'
    Now the problem is that layout is regenerated for the list action after the redirect so I get a doubled layout with the page. I may not except the list method from the layout because it will not show the page layout when listing items.

    I have searched the rails documentation and found this:
    render :action => "list", :layout => false

    But this didn't work, it caused an error.

    Do you suggest some other solution?

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't use Ajax for this. It has no advantage if you redirect anyway.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •