<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Extending the Ajax Scaffold Plugin</title>
	<atom:link href="http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/</link>
	<description>Dr Scott A. Rutherford</description>
	<lastBuildDate>Fri, 25 Nov 2011 13:08:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: gabson@gfc.no</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-278</link>
		<dc:creator>gabson@gfc.no</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-278</guid>
		<description>think theres a bug in your conditions example.

def conditions_for_collection
  [ &#039;employer_id&#039; =&gt; params[:current_employer] ]
end

makes nothing happen.

def conditions_for_users_collection
  [ &#039;employer_id&#039; =&gt; params[:current_employer] ]
end

produces an not method error.

but

def conditions_for_users_collection
  [ &#039;employer_id=?&#039;,params[:current_employer] ]
end

works.

Makes sense when you look at :conditions in the rails api
gabs</description>
		<content:encoded><![CDATA[<p>think theres a bug in your conditions example.</p>
<p>def conditions_for_collection<br />
  [ 'employer_id' =&gt; params[:current_employer] ]<br />
end</p>
<p>makes nothing happen.</p>
<p>def conditions_for_users_collection<br />
  [ 'employer_id' =&gt; params[:current_employer] ]<br />
end</p>
<p>produces an not method error.</p>
<p>but</p>
<p>def conditions_for_users_collection<br />
  [ 'employer_id=?',params[:current_employer] ]<br />
end</p>
<p>works.</p>
<p>Makes sense when you look at :conditions in the rails api<br />
gabs</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Rutherford</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-279</link>
		<dc:creator>Scott Rutherford</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-279</guid>
		<description>Hi Gabson,

Well spotted. I have updated the post.

Thanks
Scott.</description>
		<content:encoded><![CDATA[<p>Hi Gabson,</p>
<p>Well spotted. I have updated the post.</p>
<p>Thanks<br />
Scott.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gabson@gfc.no</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-280</link>
		<dc:creator>gabson@gfc.no</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-280</guid>
		<description>Happy to help :)
By the way, I was in such a rush before, I forgot to mention how much I appreciate your work.

Thank you very very much for all your time and efford! You guys have done a great job.

Now, back to finding out how I can maintain parent - child relationships between scaffolds, when editing.

Cheers,
Gabs.</description>
		<content:encoded><![CDATA[<p>Happy to help <img src='http://www.sarutherford.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
By the way, I was in such a rush before, I forgot to mention how much I appreciate your work.</p>
<p>Thank you very very much for all your time and efford! You guys have done a great job.</p>
<p>Now, back to finding out how I can maintain parent &#8211; child relationships between scaffolds, when editing.</p>
<p>Cheers,<br />
Gabs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haim</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-281</link>
		<dc:creator>Haim</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-281</guid>
		<description>Hi,

Great work. I needed to allow users to edit only the records belonging to them, so I changed the ajax_scaffold.rb to implement a do_edit method. Then I overrode it in my controller.I am not sure this is the best way to do this but it worked. Here is my modified code:

def edit#{suffix}
	begin
	  do_edit#{suffix}
	rescue
	  flash[:error], @successful  = $!.to_s, false
	end
	return render#{suffix}_template(:action =&gt; &#039;edit.rjs&#039;) if request.xhr?
	if @successful
	  @options = { :scaffold_id =&gt; params[:scaffold_id], :action =&gt; &quot;update&quot;, :id =&gt; params[:id] }
	  render#{suffix}_template(:action =&gt; &quot;_new_edit.rhtml&quot;, :layout =&gt; true)
	else
	  #{prefix}return_to_main
	end
end

def do_edit#{suffix}
	@#{singular_name} = #{class_name}.find(params[:id])
	@successful = !@#{singular_name}.nil?
end</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Great work. I needed to allow users to edit only the records belonging to them, so I changed the ajax_scaffold.rb to implement a do_edit method. Then I overrode it in my controller.I am not sure this is the best way to do this but it worked. Here is my modified code:</p>
<p>def edit#{suffix}<br />
	begin<br />
	  do_edit#{suffix}<br />
	rescue<br />
	  flash[:error], @successful  = $!.to_s, false<br />
	end<br />
	return render#{suffix}_template(:action =&gt; &#8216;edit.rjs&#8217;) if request.xhr?<br />
	if @successful<br />
	  @options = { :scaffold_id =&gt; params[:scaffold_id], :action =&gt; &quot;update&quot;, :id =&gt; params[:id] }<br />
	  render#{suffix}_template(:action =&gt; &quot;_new_edit.rhtml&quot;, :layout =&gt; true)<br />
	else<br />
	  #{prefix}return_to_main<br />
	end<br />
end</p>
<p>def do_edit#{suffix}<br />
	@#{singular_name} = #{class_name}.find(params[:id])<br />
	@successful = !@#{singular_name}.nil?<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Rutherford</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-282</link>
		<dc:creator>Scott Rutherford</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-282</guid>
		<description>@gabson: No problem. The relationship thing is a bit of a tricky one isn&#039;t it. We haven&#039;t really looked at how to implement it in the plugin yet. There is some info on then &quot;wiki&quot;:http://ajaxscaffold.stikipad.com about doing it with the generator. Let me know how you get on.

@Haim: Your approach seems reasonable (EDIT: although see my later comment on why changing the plugin isn&#039;t a good idea), we probably should of included an extension point for the edit, and maybe for the new. I think I probably would call your do_edit method something different as it isn&#039;t actually doing the edit. Maybe find#{suffix} or something that actually implies the action (see below). I take it you actually meant you updated the code in the ajax_scaffold_plugin.rb file.

&lt;pre&gt;
def edit#{suffix}
  begin
    find#{suffix}
  rescue
    flash[:error], @successful  = $!.to_s, false
  end

  [REST OF METHOD STAYS THE SAME]
end

def find#{suffix}
  @#{singular_name} = #{class_name}.find(params[:id])
  @successful = !@#{singular_name}.nil?
end
&lt;/pre&gt;

Cheers guys,
Scott.</description>
		<content:encoded><![CDATA[<p>@gabson: No problem. The relationship thing is a bit of a tricky one isn&#8217;t it. We haven&#8217;t really looked at how to implement it in the plugin yet. There is some info on then &quot;wiki&quot;:<a href="http://ajaxscaffold.stikipad.com" rel="nofollow">http://ajaxscaffold.stikipad.com</a> about doing it with the generator. Let me know how you get on.</p>
<p>@Haim: Your approach seems reasonable (EDIT: although see my later comment on why changing the plugin isn&#8217;t a good idea), we probably should of included an extension point for the edit, and maybe for the new. I think I probably would call your do_edit method something different as it isn&#8217;t actually doing the edit. Maybe find#{suffix} or something that actually implies the action (see below). I take it you actually meant you updated the code in the ajax_scaffold_plugin.rb file.</p>
<p>&lt;pre&gt;<br />
def edit#{suffix}<br />
  begin<br />
    find#{suffix}<br />
  rescue<br />
    flash[:error], @successful  = $!.to_s, false<br />
  end</p>
<p>  [REST OF METHOD STAYS THE SAME]<br />
end</p>
<p>def find#{suffix}<br />
  @#{singular_name} = #{class_name}.find(params[:id])<br />
  @successful = !@#{singular_name}.nil?<br />
end<br />
&lt;/pre&gt;</p>
<p>Cheers guys,<br />
Scott.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haim Schlesinger</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-283</link>
		<dc:creator>Haim Schlesinger</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-283</guid>
		<description>Yes, I did change it in the ajax_scaffold_plugin.rb, and yes your naming is probably better. I also added it to the destroy method, so I placed the find method in the private section, and created the following two methods, each right after the relevant main method. Here is edit:

&lt;pre&gt;
def edit#{suffix}
  begin
    prepare_edit#{suffix}
  rescue
    flash[:error], @successful  = $!.to_s, false
  end

  [REST OF METHOD STAYS THE SAME]
end

def prepare_edit#{suffix}
    find#{suffix}
end
&lt;/pre&gt;

Thanks.

Haim

Btw, how can you format the code here like you did?</description>
		<content:encoded><![CDATA[<p>Yes, I did change it in the ajax_scaffold_plugin.rb, and yes your naming is probably better. I also added it to the destroy method, so I placed the find method in the private section, and created the following two methods, each right after the relevant main method. Here is edit:</p>
<p>&lt;pre&gt;<br />
def edit#{suffix}<br />
  begin<br />
    prepare_edit#{suffix}<br />
  rescue<br />
    flash[:error], @successful  = $!.to_s, false<br />
  end</p>
<p>  [REST OF METHOD STAYS THE SAME]<br />
end</p>
<p>def prepare_edit#{suffix}<br />
    find#{suffix}<br />
end<br />
&lt;/pre&gt;</p>
<p>Thanks.</p>
<p>Haim</p>
<p>Btw, how can you format the code here like you did?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haim Schlesinger</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-284</link>
		<dc:creator>Haim Schlesinger</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-284</guid>
		<description>Is there a way to override this code so it will redirect to list instead of table?:

&lt;pre&gt;
verify :method =&gt; :post, :only =&gt; [ :destroy#{suffix}, :create#{suffix}, :update#{suffix} ],
       :redirect_to =&gt; { :action =&gt; :#{prefix}table }
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Is there a way to override this code so it will redirect to list instead of table?:</p>
<p>&lt;pre&gt;<br />
verify :method =&gt; :post, <img src='http://www.sarutherford.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly =&gt; [ :destroy#{suffix}, :create#{suffix}, :update#{suffix} ],<br />
       :redirect_to =&gt; { :action =&gt; :#{prefix}table }<br />
&lt;/pre&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Rutherford</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-285</link>
		<dc:creator>Scott Rutherford</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-285</guid>
		<description>Hi Haim,

For the formatting you just wrap the code in &#039;pre&#039; tags (I added them to your comment).

As for overriding the verify method, I think if you just redefine it in your controller then that will be picked up. All of those post actions are from ajax calls though so you need to be sure thats what you want / need to do.

Scott.</description>
		<content:encoded><![CDATA[<p>Hi Haim,</p>
<p>For the formatting you just wrap the code in &#8216;pre&#8217; tags (I added them to your comment).</p>
<p>As for overriding the verify method, I think if you just redefine it in your controller then that will be picked up. All of those post actions are from ajax calls though so you need to be sure thats what you want / need to do.</p>
<p>Scott.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Rutherford</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-286</link>
		<dc:creator>Scott Rutherford</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-286</guid>
		<description>@Haim: Just a point, but if you can (and I see no reason why you can&#039;t) you should really implement these changes in your controller and not change the plugin code. That way you can upgrade without fear of breaking anything.

With this particular change I may well include something like it, but it would be better to override the plugin functionality on a controller by controller basis.</description>
		<content:encoded><![CDATA[<p>@Haim: Just a point, but if you can (and I see no reason why you can&#8217;t) you should really implement these changes in your controller and not change the plugin code. That way you can upgrade without fear of breaking anything.</p>
<p>With this particular change I may well include something like it, but it would be better to override the plugin functionality on a controller by controller basis.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad Pytel</title>
		<link>http://www.sarutherford.com/2006/09/06/extending-the-ajax-scaffold-plugin/comment-page-1/#comment-287</link>
		<dc:creator>Chad Pytel</dc:creator>
		<pubDate>Wed, 06 Sep 2006 13:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.caronsoftware.com/2007/11/25/extending-the-ajax-scaffold-plugin#comment-287</guid>
		<description>It doesn&#039;t look like your conditions_for_users_collection example has been updated to change the &#039;=&gt;&#039; to &#039;,&#039;

thanks,
-Chad</description>
		<content:encoded><![CDATA[<p>It doesn&#8217;t look like your conditions_for_users_collection example has been updated to change the &#8216;=&gt;&#8217; to &#8216;,&#8217;</p>
<p>thanks,<br />
-Chad</p>
]]></content:encoded>
	</item>
</channel>
</rss>

