Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hobo_controller makes it unnecessarily hard to implement JSON APIs #188

Open
stevemadere opened this issue Sep 11, 2016 · 0 comments
Open

Comments

@stevemadere
Copy link

There are a couple of places where respond_to blocks are hard-coded
to only handle HTML and JS responses.

As a result, it is unnecessarily difficult to implement a hobo controller
that can handle JSON requests.

Really, it should work like any other controller does where all you have
to do is add this to your controller declaration:

respond_to :json, :html

Instead, one has to over-ride every single controller action manually and put
in your own respond_to block. What's that use of Hobo at that point?

In some places, Hobo just assumes that if the request is not an AJAX request,
the response should be HTML.

The specific places where this assumption is hard-coded are:
Hobo::Controller::Model#permission_denied
Hobo::Controller::Model#create_response
Hobo::Controller::Model#update_response
Hobo::Controller::Model#do_creator_response

Additionally, it often determines if it should respond with js not by looking at the requested response format but instead by checking for the mere existence of params[:render].

e.g.: In Hobo::Controller::Model#update_response

      if params[:render]
        if (params[:render_options] && params[:render_options][:errors_ok]) || valid
          hobo_ajax_response

          # Maybe no ajax requests were made
          render :nothing => true unless performed?
        else
          errors = @this.errors.full_messages.join('\n')
          message = ht(:"#{@this.class.to_s.underscore}.messages.update.error", :default=>["There was a problem with that change\\n#{errors}"], :errors=>errors)

          render :js => "alert(#{message.to_json});\n"
        end
      else

I have implemented a kludgey workaround in my hobo_turbo gem (include HoboTurbo::Workarounds::JsonResponseFix) but I'd prefer
that we get this fixed properly since my workaround does not handle custom
actions created with say index_action or show_action or auto_actions_for

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant