<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - How can I reload page without refreshing with using Ajax in Rails3]]></title>
		<link>http://railsforum.com/viewtopic.php?id=50765</link>
		<description><![CDATA[The most recent posts in How can I reload page without refreshing with using Ajax in Rails3.]]></description>
		<lastBuildDate>Mon, 15 Oct 2012 02:35:38 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[How can I reload page without refreshing with using Ajax in Rails3]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=156170#p156170</link>
			<description><![CDATA[<p>I tried these codes below. But it gives error back :( I&#039;m pretty sure that I have mistake in &quot;set_follow.js.erb&quot; but I have no idea what it is. Can anybody show me what&#039;s wrong there?</p><p>It should refresh results without reloading, if Follow(or Un-follow) button is clicked. </p><p>Here&#039;s my codes</p><p>-----------------------------------------------------------------------------------------------------------------<br />users_controller.rb </p><p>&nbsp; def set_follow <br />&nbsp; &nbsp; friend = User.find_by_username(params[:username]) <br />&nbsp; &nbsp; if f = Friendship.find(:first, :conditions =&gt; { :user_id =&gt; current_user.id, :friend_id =&gt; friend.id}) <br />&nbsp; &nbsp; &nbsp; f.destroy <br />&nbsp; &nbsp; &nbsp; flash[:notice] = &quot;Now added to follow list&quot;<br />&nbsp; &nbsp; &nbsp; respond_to do |format| <br />&nbsp; &nbsp; &nbsp; &nbsp; format.html { redirect_to set_follow } <br />&nbsp; &nbsp; &nbsp; &nbsp; format.js <br />&nbsp; &nbsp; &nbsp; end <br />&nbsp; &nbsp; &nbsp; #redirect_to :back <br />&nbsp; &nbsp; else <br />&nbsp; &nbsp; &nbsp; Friendship.create(:user_id =&gt; current_user.id, :friend_id =&gt; friend.id) <br />&nbsp; &nbsp; &nbsp; flash[:error] = &quot;Now deleted from follow list&quot;<br />&nbsp; &nbsp; &nbsp; respond_to do |format| <br />&nbsp; &nbsp; &nbsp; &nbsp; format.html { redirect_to set_follow } <br />&nbsp; &nbsp; &nbsp; &nbsp; format.js <br />&nbsp; &nbsp; &nbsp; end <br />&nbsp; &nbsp; &nbsp; #redirect_to :back <br />&nbsp; &nbsp; end&nbsp; &nbsp; &nbsp;<br />&nbsp; end </p><br /><p>-----------------------------------------------------------------------------------------------------------------<br /> users/index.html.erb</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;follow_status&quot;&gt; <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;% if user_signed_in? &amp;&amp; current_user.friends.find_by_id(user.id) %&gt;&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;%= link_to sanitize(&#039;&lt;i class=&quot;icon-remove icon-white&quot;&gt;&lt;/i&gt; &#039;) + &#039;Un-Follow&#039;, follow_user_path(user.username), :class =&gt; &#039;btn&#039;, remote: true %&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;% elsif current_user != user %&gt; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;%= link_to sanitize(&#039;&lt;i class=&quot;icon-ok icon-white&quot;&gt;&lt;/i&gt; &#039;) + &#039;Follow&#039;, follow_user_path(user.username), :class =&gt; &#039;btn btn-primary&#039;, remote: true %&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;% end %&gt; <br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt; </p><br /><p>-----------------------------------------------------------------------------------------------------------------<br />set_follow.js.erb</p><p>$(&quot;#follow_status&quot;).html(&quot;&lt;%= escape_javascript(render f) %&gt;&quot;);</p>]]></description>
			<author><![CDATA[dummy@example.com (KEYs)]]></author>
			<pubDate>Mon, 15 Oct 2012 02:35:38 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=156170#p156170</guid>
		</item>
	</channel>
</rss>
