Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax action won't reflect on appearance but the value. Why?
    primarykey
    data
    text
    <p>I'm using Rails3. Now trying to implement follow button in index.html.erb just like twitter.<br> It shows member list and their follow buttons.<br> It looks okay but if I press any of those follow button, appearance doesn't change.<br> It should changes follow to un-follow right away.<br> I have no idea why it does. But if I reload the page, it shows correct status.</p> <p>follows_controller.rb</p> <pre><code>class FollowsController &lt; ApplicationController def create @user = User.find(params[:user_id]) current_user.follow(@user) respond_to do |format| format.js {render :action=&gt;"create.js"} end end def destroy @user = User.find(params[:user_id]) current_user.stop_following(@user) respond_to do |format| format.js {render :action=&gt;"destroy.js"} end end end </code></pre> <p>views/users/_follow_user.html.erb</p> <pre><code>&lt;% unless user == current_user %&gt; &lt;% if current_user.following?(user) %&gt; &lt;%= button_to("Un-Follow", user_follow_path(user.to_param, current_user.get_follow(user).id), :method =&gt; :delete, :remote =&gt; true, :class =&gt; 'btn') %&gt; &lt;% else %&gt; &lt;%= button_to("Follow", user_follows_path(user.to_param), :remote =&gt; true, :class =&gt; 'btn btn-primary') %&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>views/users/create.js.erb</p> <pre><code>$('.follow_user[data-user-id="&lt;%=@user.id%&gt;"]').html('&lt;%= escape_javascript(render :partial =&gt; "follow_user", :locals =&gt; {:user =&gt; @user}) %&gt;'); #jQuery </code></pre> <p>views/users/destroy.js.erb</p> <pre><code>$('.follow_user[data-user-id="&lt;%=@user.id%&gt;"]').html('&lt;%= escape_javascript(render :partial =&gt; "follow_user", :locals =&gt; {:user =&gt; @user}) %&gt;'); #jQuery </code></pre> <p>views/users/index.html.erb</p> <pre><code>&lt;%- model_class = User.new.class -%&gt; &lt;div class="page-header"&gt; &lt;h1&gt;&lt;%=t '.title', :default =&gt; model_class.model_name.human.pluralize %&gt;&lt;/h1&gt; &lt;/div&gt; &lt;% @from %&gt; &lt;h3&gt;tag cloud&lt;/h3&gt; &lt;% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %&gt; &lt;%= link_to tag.name, {:action=&gt;'index', :tag=&gt;tag.name}, :class =&gt; css_class%&gt; &lt;% end %&gt; &lt;%= paginate @users %&gt; &lt;table class="table table-condensed"&gt; &lt;thead&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;% @users.each do |user| %&gt; &lt;div class="memberListBox"&gt; &lt;div class="memberList"&gt; &lt;p class="name"&gt;&lt;span&gt;&lt;%= user.user_profile.nickname %&gt;&lt;/span&gt;(&lt;%= user.user_profile.age %&gt;)&lt;/p&gt; &lt;p class="size"&gt;&lt;%= user.username %&gt;&lt;/p&gt; &lt;p class="img"&gt; &lt;% if user.user_profile.user_avatar? %&gt; &lt;%= image_tag(user.user_profile.user_avatar.url(:thumb),:height =&gt; 100, :width =&gt; 100, :class =&gt; 'img-polaroid' ) %&gt; &lt;% else %&gt; &lt;%= image_tag('nophoto.gif',:height =&gt; 100, :width =&gt; 100, :class =&gt; 'img-polaroid' ) %&gt; &lt;% end %&gt; &lt;/p&gt; &lt;div class="introduction"&gt; &lt;%= user.user_profile.introduction %&gt; &lt;/div&gt; &lt;% if user_signed_in? &amp;&amp; current_user!=user %&gt; &lt;div id="follow_user"&gt; &lt;%= render :partial =&gt; "follow_user", :locals =&gt; {:user =&gt; user} %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;%= link_to sanitize('&lt;i class="icon-pencil icon-white"&gt;&lt;/i&gt; ') + 'Message', new_messages_path(user.username), :class =&gt; 'btn btn-primary' %&gt; &lt;%= link_to sanitize('&lt;i class="icon-user icon-white"&gt;&lt;/i&gt; ') + 'Profile', show_user_path(:username =&gt; user.username, :breadcrumb =&gt; @from), :class =&gt; 'btn btn-info' %&gt; &lt;/div&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>response content</p> <p><code>$('#follow_user').html(' &lt;form action=\"/users/1/follows\" class=\"button_to\" data-remote=\"true\" method=\"post\"&gt;&lt;div&gt;&lt;input class=\"btn btn-primary\" type=\"submit\" value=\"Follow\" /&gt;&lt;input name=\"authenticity_token\" type=\"hidden\" value=\"G/taOUeWy2gumhWUi10cPvECAmYLQdhQ2/eGGMJwvPE=\" /&gt;&lt;\/div&gt;&lt;\/form&gt;</code>\n');</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload