In my application, I am using Michael Hartl's Follow/Unfollow process using 
javascript. It works fine on my Mac running Chrome, Firefox and Safari, 
locally and from Heroku. On the iPhone (running directly on my iPhone via 
Heroku or locally using iOS Simulator) things get strange. Things work ok 
to unfollow. But to follow, I click on the blue button that says "Follow". 
The controller action is fine, I actually get to follow the intended user. 
But the button, instead of changing to white and saying "Following", 
 behaves as if the cursor is hovering over it. That is, it does not change 
to the other button, only its color is greyed. Only when I click something 
else, does the button change to its correct setting. It's as though the 
rendering is not done after the follow action is executed.

When I rake assets:precompile and run with config.assets.compile = false 
(which is what I want to do in production), after I click the Follow 
button, it throws me back to a totally different page, one which I only 
access under two circumstances- (1) it's the page that the create action of 
my users_controller would throw me if it could not save a new user, and (2) 
if the signed_in_user condition fails.

Here is the code (it will look very familiar).

follow_form.mobile.erb

<% unless current_user?(@user) %>
  <div id="<%[email protected] %>">
  <% if current_user.following?(@user) %>
    <%= render 'unfollow' %>
  <% else %>
    <%= render 'follow' %>
  <% end %>
  </div><% end %>

_follow.mobile.erb

<%= form_for(current_user.relationships.build(followed_id: @user.id),
             remote: true) do |f| %>
  <div><%= f.hidden_field :followed_id %></div>
  <%= f.submit "Follow", class: "btn btn-primary btn-small" %><% end %>

_unfollow.mobile.erb

<%= form_for(current_user.relationships.find_by_followed_id(@user),
             html: { method: :delete },
             remote: true) do |f| %>
  <%= f.submit "Following", class: "btn btn-small", data: {:confirm => "Are you 
sure you want to unfollow this user?"} %><% end %>

create.js.erb

$("#<%[email protected] %>").html("<%= escape_javascript(render('users/unfollow')) %>")
$("#followers").html('<%= @user.followers.count %>')

destroy.js.erb

$("#<%[email protected] %>").html("<%= escape_javascript(render('users/follow')) %>")
$("#followers").html('<%= @user.followers.count %>')

relationships_controller.rb

class RelationshipsController < ApplicationController
  before_filter :signed_in_user

  respond_to :html, :js

  def create
    @user = User.find(params[:relationship][:followed_id])
    current_user.follow!(@user)
    respond_with @user
  end

  def destroy
    @user = Relationship.find(params[:id]).followed
    current_user.unfollow!(@user)
    respond_with @user
  endend 


-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to