jquery - How can I output a helper from erb.js in rails 3? -


this have in erb.js file....but doesn't work:

  1 //update message   2 $('#follow-update').html("<%= follow_button(@question) %>") 

follow_button helper:

20   def follow_button(resource)  21       22     type = resource.class.name  23     follow_status = current_user.following?(resource)  24   25     verb = "follow" if follow_status == false  26     verb = "unfollow" if follow_status == true  27   28     content_tag(:div, :class => "follow-button")  29       link_to "#{verb} #{type} ", follow_path(:followed_type => type,  30                                                   :followed_id => resource.id,  31                                                   :follow_verb => verb),   32                                                   :class => "button",  33                                                   :remote => true  34     end  35   end  36 end 

the helper stand-alone works fine, want update button. perhaps there's way update text without replacing whole helper?

create partial holds contains helper.

for example: '/wherever/_follow_button.html.erb'

inside, call helper:

<%= follow_button(question) %> 

next, render using js.

$('#some-id').html("<%= escape_javascript(render('/wherever/follow_button', :question => @question)) %>"); 

there ways make more efficient helps now.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -