apotonick / apotomo

MVC Components for Rails.
http://apotomo.de
653 stars 68 forks source link

Custom response code for ajax events support #147

Closed mbajur closed 10 years ago

mbajur commented 10 years ago

Hello! I'm trying to use Apotomo to create a simple tabable widget. It's not using any database data and it's not querying it. Just a partials loaded to tab contents. My widget code looks like that:

class VideosSidebarWidget < Apotomo::Widget

  responds_to_event :show_filters, with: :show_filters

 # ...

  def display
    render partial: 'collapsed'
  end

  def show_filters
    replace view: '_filters'
  end

  # ...

end

And now, to the point - i need to use ajax events to add some animation stuff to my logic but the problem is, that show_filters returns 304 Not Modified status which breaks the on('ajax:complete') and any other javascript event (only beforeSend works) cause it seems, that they expect different status codes in request response. (more info on rails ajax events: http://bit.ly/1iVgLpN)

The question is - can i set a custom response code for my widget methods? Thanks in advance!

mbajur commented 10 years ago

After further investigation, i've found that 304 should be handled by ajax:success (and ajax:complete) events but it's not for some reason. The question is - is that Apotomo's fault or not?

apotonick commented 10 years ago

Hi Mike!

The generation of the response is done here: https://github.com/apotonick/apotomo/blob/master/lib/apotomo/rails/controller_methods.rb#L70

I totally agree that this could be a little bit more customizable - play around with it and tell me what settings would work for you.

mbajur commented 10 years ago

Ok, it turned out that it was caused by something else. complete and success events are not working cause i'm replacing the button element (on which i'm listening for those events) with apotomo. That's a known UJS issue and has nothing to do with Apotomo.

Thanks for your help!