Ajax调用后,我无法让局部变量显示在partials内部。这里是我的设置:使用Ajax渲染局部变量,Rails 4
查看 - index.html.erb
查看谐音/ _index_follow_button.html.erb
查看 - follow_button.js.erb
$('.index_follow_button').html(' 'partials/index_follow_button.html.erb', :locals => {:artist => artist}) %>');
相信这是其中误差是
控制器 - 使用:artist => artistrelationships_controller.rb
def create
@relationship = ArtistRelationship.new
@relationship.fan_id = current_fan.id
@relationship.artist_id = Artist.friendly.find(params[:artist_id]).id
@artist = Artist.friendly.find(params[:artist_id])
if @relationship.save
respond_to do |format|
format.html { redirect_to (:back) }
format.js { render :action => "follow_button" }
end
else
redirect_to root_url
end
end
def destroy
current_fan.unfollow_artist(Artist.friendly.find(params[:artist_id]))
@artist = Artist.friendly.find(params[:artist_id])
respond_to do |format|
format.html { redirect_to (:back) }
format.js { render :action => "follow_button" }
end
end
在索引页,部分显示完全正常,但在JavaScript页面中没有发生同样的事情,但我保持getti ng相同的错误 -
ActionView::Template::Error (undefined local variable or method `artist' for #:0x6f43968>)
任何想法?