Twitter Bootstrap Rails button dropdown no responding to AJAX

后端 未结 2 1689
陌清茗
陌清茗 2020-12-19 23:36

I have a Rails 4 app that is using Bootstrap. I am creating a dashboard page that shows buttons that are color coded to represent the status of the tool it represents. The H

2条回答
  •  抹茶落季
    2020-12-20 00:23

    Probably this is not answer, but I will give my suggestions. First of all you don't need two actions making same things. Try this

    Controller

    def in_service
     @tool.update(:in_service => params[:in_service])
     @success = params[:in_service]
     respond_to do |format|
       format.html { redirect_to(root_path) }
       format.js
       end
    end
    

    In view add parameters to query

    View

    
    

    Don't need to listen ajax bindings

    js.erb

    <% if @success %>
      $('.btn').addClass('.btn-success').removeClass('.btn-warning');
    <% else %>
        $('.btn').addClass('.btn-warning').removeClass('.btn-success');
    <% end %>
    

提交回复
热议问题