javascript - Rendering js.erb in rails -


i want try js.erb if working?

here view posts/index trigger

 <%= link_to "like", {:controller => 'post', :id => post , :action =>'like'}, class: "btn btn-danger btn-xs", remote: true %> 

my post controller

def @user = current_user @post.liked_by(@user) redirect_to posts_path respond_to |format|   format.html {redirect_to posts_path}   format.js { render :action => 'stablelike' }  end end 

and js.erb test

alert("working"); 

and error: when inspect chrome

abstractcontroller::doublerendererror @ /post/like/85

render and/or redirect called multiple times in action. please note may call render or redirect, , @ once per action. note neither redirect nor render terminate execution of action, if want exit action after redirecting, need "redirect_to(...) , return".

app/controllers/posts_controller.rb, line 83

 ``` ruby  78       @user = current_user  79       @post.liked_by(@user)  80       redirect_to posts_path  81       respond_to |format|  82         format.html {redirect_to posts_path} 

83 format.js { render :action => 'stablelike' } 84
85 end 86 end 87

in controller action, neither render nor redirect_to stops execution of action. why you're getting doublerendererror. remove first redirect_to , should fine.

def   @user = current_user   @post.liked_by(@user) # unsure you're trying accomplish here   respond_to |format|     format.html { redirect_to posts_path }     format.js { render :stablelike }   end end 

if doesn't work, have not setup stablelike action respond xhr requests. can by

def stablelike   respond_to  |format|     # other formats     format.js # default looks `stablelike.js.erb`   end end 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -