<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>armisael.silix.org &#187; ruby on rails</title>
	<atom:link href="http://armisael.silix.org/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://armisael.silix.org</link>
	<description>Armisael's scientific world</description>
	<lastBuildDate>Sat, 28 Jan 2012 13:35:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ruby on Rails: remote functions do not work</title>
		<link>http://armisael.silix.org/2009/06/ruby-on-rails-remote-functions-do-not-work/</link>
		<comments>http://armisael.silix.org/2009/06/ruby-on-rails-remote-functions-do-not-work/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 09:56:37 +0000</pubDate>
		<dc:creator>Armisael</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[remote form tag]]></category>
		<category><![CDATA[remote function]]></category>

		<guid isPermaLink="false">http://armisael.silix.org/?p=57</guid>
		<description><![CDATA[Your remote_function or remote_form_tag could stop working if you use jQuery into your Ruby on Rails project. This is because the jQuery $ function is different from the prototype one, and RoR uses some particular function that is not available with jQuery. For example, you can get an error like this submitting your remote_form_tag: $(form).getElementsByTagName &#8230; </p><p><a class="more-link block-button" href="http://armisael.silix.org/2009/06/ruby-on-rails-remote-functions-do-not-work/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Your <em>remote_function</em> or <em>remote_form_tag</em> could stop working if you use jQuery into your Ruby on Rails project. This is because the jQuery $ function is different from the prototype one, and RoR uses some particular function that is not available with jQuery.</p>
<p>For example, you can get an error like this submitting your <em>remote_form_tag</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="error" style="font-family:monospace;">$(form).getElementsByTagName is not a function
http://localhost:3000/javascripts/prototype.js?1239274532
Line 3483</pre></div></div>

<p>To solve this kind of problem, you have to use the jQuery no-conflict method, like explaned on the <a href="http://docs.jquery.com/Using_jQuery_with_Other_Libraries" target="_blank">jQuery site</a>. Simply add theese lines of code in your default layout between into a &lt;script&gt; tag:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Now, RoR can use prototype calling the default function $ and you can use jQuery using the jQuery function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#myId&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;def&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://armisael.silix.org/2009/06/ruby-on-rails-remote-functions-do-not-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails: adding custom elements in generated xml</title>
		<link>http://armisael.silix.org/2009/04/ruby-on-rails-adding-custom-elements-in-generated-xml/</link>
		<comments>http://armisael.silix.org/2009/04/ruby-on-rails-adding-custom-elements-in-generated-xml/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 15:54:57 +0000</pubDate>
		<dc:creator>Armisael</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://armisael.silix.org/?p=50</guid>
		<description><![CDATA[If you create a scaffold for your rails project, it will create for you a lot of things; for example, a way to show your object in xml format. But what about adding custom elements to that xml? I solved in this way: class MyObject &#60; ActiveRecord::Base #[...] def to_xml&#40;options=&#123;&#125;&#41; cp = attributes.clone cp&#91;&#34;something&#34;&#93; = &#8230; </p><p><a class="more-link block-button" href="http://armisael.silix.org/2009/04/ruby-on-rails-adding-custom-elements-in-generated-xml/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>If you create a scaffold for your rails project, it will create for you a lot of things; for example, a way to show your object in xml format. But what about adding custom elements to that xml?</p>
<p>I solved in this way:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> MyObject <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#008000; font-style:italic;">#[...]</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> to_xml<span style="color:#006600; font-weight:bold;">&#40;</span>options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    cp = attributes.<span style="color:#9900CC;">clone</span>
    cp<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;something&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;some value&quot;</span>
    cp<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;another thing&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">some_relation</span>.<span style="color:#9900CC;">length</span>
    cp.<span style="color:#9900CC;">to_xml</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://armisael.silix.org/2009/04/ruby-on-rails-adding-custom-elements-in-generated-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

