0

I know, the current already asked, but I can not fix it...

Gemfile

 gem 'rails', '3.2.9'
 gem 'jquery-rails' , '2.0.2'

class RelationshipsController < ApplicationController

  def create
    @user = User.find(params[:relationship][:followed_id])
    current_user.follow!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end

create.js.erb

  $("#follow_form").html("<%= escape_javascript(render('shared/unfollow')) %>")

I have partial \app\views\shared\_unfollow.html.erb

 <%= form_for current_user.relationships.find_by_followed_id(@account), 
        :html => { :method => :delete }, :remote => true do |f|%>
     <div class="actions"><%= f.submit 'unfollow' %></div>
 <% end %>

if press the button, the state does not change. Try add ".html_safe" doesn't work too.

But if I do

$("#follow_form").html("bla bla bla")

or

$("#follow_form").html("<%= 10+10 %>")

it's work

obakhtin
  • 15
  • 3

1 Answers1

1

Try to change

$("#follow_form").html("<%= escape_javascript(render('shared/unfollow')) %>")

to

$("#follow_form").html('<%= escape_javascript(render("shared/unfollow")) %>');

Errors may be caused by invalid syntax of the javascript, so your javascript will not be executed. You will not see the erorrs in any browsers. But you can used Firefox to see the Ajax response.

I faced the similar problem before

Community
  • 1
  • 1
code4j
  • 4,208
  • 5
  • 34
  • 51
  • try change " to ' , no ganges. But firefox console write "HTTP/1.1 500 Internal Server Error", it is something :) – obakhtin Dec 19 '12 at 17:14
  • I have added `;` behind just now ,haha. See the log file, does the application execute that JS file? – code4j Dec 19 '12 at 17:23
  • Also Download the firebug and check the ajax response comeback – code4j Dec 19 '12 at 17:24
  • greate! The button changes state. Apparently, where it lost in the variables. Appointed afresh and earned. but sent two requests, well, that I'll deal. Thanks – obakhtin Dec 19 '12 at 17:47
  • it lost in the variables?? – code4j Dec 19 '12 at 18:07
  • 'ActionView::Template::Error (undefined method `model_name' for NilClass:Class): 1: <%= form_for current_user.relationships.find_by_followed_id(@account), :html => { :method => :delete }, :remote => true do |f|%> 2:
    <%= f.submit t(:button_unfollow) %>
    3: <% end %> app/views/shared/_unfollow.html.erb:1:in `_app_views_shared__unfollow_html_erb__850533283_35511012' app/views/relationships/create.js.erb:1:in `_app_views_relationships_create_js_erb___239460557_35579604' app/controllers/relationships_controller.rb:7:in `create''
    – obakhtin Dec 19 '12 at 18:16