<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;How about some ajaxified links or buttons?&lt;/p&gt;
&lt;p&gt;Inside your &lt;span class=&quot;caps&quot;&gt;DRYML&lt;/span&gt; you can do this&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
          &amp;lt;%= link_to_remote( &quot;remove project&quot;,
              :url =&amp;gt; { :action =&amp;gt; :rem_proj, :id =&amp;gt; this.id } )
          %&amp;gt;  
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Which creates a link to call a custom controller method rem_proj.  So in the controller we will need:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
class UsersController &amp;lt; ApplicationController


  def rem_proj
    mp = Project.find(params[&quot;id&quot;])
    mp.status = &quot;hidden&quot;
    mp.save
  end

&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;But what if you want a partial update on the page to make the hidden project disappear?  Lets define a tag for the content of this page in app/views/taglib/application.dryml&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
&amp;lt;def tag=&quot;user-projects&quot;&amp;gt;&lt;/p&gt;
&lt;section part=&quot;userproject&quot;&gt;
&lt;section if=&quot;&amp;(not (@new_projects.nil? or @new_projects.length==0))&quot;&gt;
	  &lt;h1&gt;New Projects&lt;/h1&gt;			  
&lt;table-plus with=&quot;&amp;@new_projects&quot; fields=&quot;this,activity_type,done_by&quot;&gt;
&lt;header: replace/&gt;
&lt;p&gt;&lt;controls:&gt;&lt;br /&gt;
          &amp;lt;%= link_to_remote( &amp;#8220;remove project&amp;#8221;,&lt;br /&gt;
              :update =&amp;gt; &amp;#8220;userproject&amp;#8221;,&lt;br /&gt;
              :url =&amp;gt; { :action =&amp;gt; :rem_proj, :id =&amp;gt; this.id } )&lt;br /&gt;
          %&amp;gt;&lt;/p&gt;
&lt;/controls:&gt;
&lt;p&gt;&lt;empty-message:&gt;&lt;br /&gt;
          No projects&lt;/p&gt;
&lt;/empty-message:&gt;
&lt;/table-plus&gt;
&lt;/section&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/section&gt;
&lt;/def&gt;
&lt;p&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And then call it from the show.dryml&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
&amp;lt;show-page&amp;gt;
  &amp;lt;content-body:&amp;gt;
       &amp;lt;user-projects/&amp;gt;
  &amp;lt;/content-body:&amp;gt;
&amp;lt;/show-page&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Now for the controller code:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
  def show
    @user = current_user
    @new_projects      = @user.new_projects       if params[&quot;sort&quot;].nil?
    @new_projects      = @user.new_projects.sort      
              {|a,b| a[params[&quot;sort&quot;]] &amp;lt;=&amp;gt; b[params[&quot;sort&quot;]]} unless params[&quot;sort&quot;].nil?
  end&lt;/p&gt;
def rem_proj
mp = Project.find(params[&amp;#8220;id&amp;#8221;].to_s)
mp.status = &amp;#8220;hidden&amp;#8221;
mp.save
@user = current_user
@new_projects = @user.new_projects
render :partial =&amp;gt; &amp;#8220;userproject&amp;#8221;, :object =&amp;gt; @new_projects
end
&lt;p&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
Note the &amp;#8220;userproject&amp;#8221;  we will need a partial template for this.&lt;/p&gt;
&lt;p&gt;The template gets named _userporject.dryml and goes in the views/&lt;model&gt; directory for the controller.&lt;br /&gt;
&lt;em&gt;userproject.dryml&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
&amp;lt;% 
  @new&lt;/em&gt;projects = userproject&lt;br /&gt;
%&amp;gt;&lt;/p&gt;
&lt;user-projects/&gt;
&lt;p&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Now when the user clicks the link_to_remote control it will ajax a request to the server and then receive and updated partial page with the hidden record removed.&lt;/p&gt;
&lt;p&gt;There is more going on here than I have described so email the hobo-users google group if you have questions.&lt;/p&gt;</body>
  <created-at type="datetime">2008-10-13T15:19:45-07:00</created-at>
  <id type="integer">66887</id>
  <permalink>ajax</permalink>
  <repository-id type="integer">3773</repository-id>
  <title>Ajax</title>
  <updated-at type="datetime">2008-10-13T15:37:34-07:00</updated-at>
  <user-id type="integer">22366</user-id>
</wiki>
