0

This code is written in a controller method.

@votetype="up"
@video = Video.find(params[:vid])
@video.up -= 1
@video.total -= 1
@video.save
ld.ld = 0
ld.save
respond_to do |format|
  format.js
end

How do I access @votetype in a .js.erb file inside an if condition?

4

2 回答 2

0

.js.erb file:

if(<%=@votetype=='up'%>){
  //js code here
}

或者

 <%if @votetype=='up'%>
    // js code
 <%end%>
于 2013-07-15T07:22:11.693 回答
0

在 js.erb 文件中,您可以像这样检查条件

<% if @votetype.eql?("up") %>
/* js code */
<% else %>
/* js  code */
<% end %>
于 2013-07-15T07:22:58.677 回答