Rails Javascript链接
在我的rails应用程序中,我有两个Rails Javascript链接,javascript,ruby-on-rails,action,link-to,Javascript,Ruby On Rails,Action,Link To,在我的rails应用程序中,我有两个链接到,这两个链接显然都有作用。当我 <% if Excont.where(:user_id=> current_user,:movie_id => @movie.id,:actionall => '2').includes(:user).all.count == 0%> <tr style="border-top: none; "> <td> <%= link_to('Ma
链接到,这两个链接显然都有作用。当我
<% if Excont.where(:user_id=> current_user,:movie_id => @movie.id,:actionall => '2').includes(:user).all.count == 0%>
<tr style="border-top: none; ">
<td>
<%= link_to('Mark as action', {:controller => :excont, :action => 'thisisanaction', :id=> @movie.id, :actionall=>'2'}, :method => :post, :remote => true, :disable_with => 'Updating...') %>
</td>
</tr>
<% else %>
<tr style="border-top: none;">
<td>
<%= link_to('Unmark as action', {:controller => :excont, :action => 'removethisisanaction', :id=> @movie.id, :actionall=>'2'}, :method => :post, :remote => true, :disable_with => 'Updating...') %>
</td>
</tr>
<% end %>
当前用户,:movie\u id=>@movie.id,:actionall=>'2')。包括(:user)。all.count==0%>
:excont,:action=>'thisisanaction',:id=>@movie.id,:actionall=>'2'},:method=>:post,:remote=>true,:disable_with=>'updateing…')%>
:excont,:action=>'removethisisanaction',:id=>@movie.id,:actionall=>'2'},:method=>:post,:remote=>true,:禁用_=>'updateing…')%>
当我点击第一个链接到
(thisisanaction)时,它运行更新…
,然后返回到标记为操作
,如果我重新加载,它将更改为取消标记为操作
我要问的是如何从
标记为操作
->更新…
->取消标记为操作
然后
取消标记为操作
-->更新…
->标记为操作
无需重新加载页面。我的JS代码会是什么样的我就是这样修复的
我将其放入一个名为_action.html.erb的单独文件中
<% if Excont.where(:user_id=> current_user,:movie_id => @movie.id,:actionall => '2').includes(:user).all.count == 0%>
<tr style="border-top: none; ">
<td>
<%= link_to('Mark as action', {:controller => :excont, :action => 'thisisanaction', :id=> @movie.id, :actionall=>'2'}, :method => :post, :remote => true, :disable_with => 'Updating...') %>
</td>
</tr>
<% else %>
<tr style="border-top: none;">
<td>
<%= link_to('Unmark as action', {:controller => :excont, :action => 'removethisisanaction', :id=> @movie.id, :actionall=>'2'}, :method => :post, :remote => true, :disable_with => 'Updating...') %>
</td>
</tr>
<% end %>
在您希望按钮显示的视图中添加此项
<div class="excontaction">
<%= render 'layouts/action' %>
</div>
divclass
或id
应该与您放在.js.erb
文件夹中的匹配
这应该管用
<div class="excontaction">
<%= render 'layouts/action' %>
</div>