warning: hack fix for bug 477: re rendering index page

34 views
Skip to first unread message

Bryan Larsen

unread,
Aug 18, 2009, 12:49:04 PM8/18/09
to hobo...@googlegroups.com
Hello all,

Due to our goal of API stability, we were unable to come up with a clean
fix for https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/477.

If you use `auto_actions :all, :except => [:new]` in your controller,
Hobo very conveniently places a new-form on the default index page.
This form submits to the create action. If you have validations on
your model that are violated, Hobo/Rails tries re render the form with
the errors highlighted. But Hobo 0.8.8 throws an exception trying to do so.

The error occurs because the index page expects a list of records in
this, but all of the other default pages expect 'this' to contain a
single record.

In our solution, we end up calling TWO different controller actions.
The POST calls the #create action. If #create succeeds, it redirects to
#show or whatever you've specified in :redirect as it has always done.
If it fails, it now sets @invalid_record, and then calls #index so
the context may be correctly populated.

This is a general problem. If your new-page view requires extra data
that your controller puts in @variables, that data will not be available
when your new page is rerendered due to the validation errors.

For 1.0, we're only fixing #index. We can justify the API change
because #index was broken already. If you're running into the problem
on other actions you're using custom controller actions anyways.

Post-1.0 we'll probably extend this style of behaviour to all actions.

You can review the patch on github:

http://github.com/tablatom/hobo/commit/2b616a661c75341c8c7378c3be366c2bfb9f9b4d

(A later patch removes the call to ruby-debug. I did run the
acceptance tests on the code -- the fact that it slipped in is very strange)

Bryan

Chuck Benedict

unread,
Oct 3, 2015, 8:25:14 AM10/3/15
to Hobo Users
So I have run into a use case where I need to solve a bug that is caused by this behavior.  I am using hobo 2.1.1 with ROR 4.0.13 and Ruby 2.0.  I have a form that I have extended and overriden certain fields with the hot-input tag to cause ajax updates to other fields.  When I call up a new form, ajax updates work fine.  When I cause a validation error on a new form, hobo routes to the index page and displays the errors.  All hot-input actions are also rendered as calls to the default action, index in this case, instead of new.  This then causes subsequent failures on all ajax calls because the form context is now a collection instead of a singleton.

Question...is this just as simple as tweaking the hot-input tag definition (which I recognize is not the best fix)?

Chuck Benedict

unread,
Oct 3, 2015, 8:25:14 AM10/3/15
to Hobo Users
In response to my recent reply, I fixed my problem with the following change to the hot-input tag.  I realize this probably is not the best fix, but it does work.

<extend tag="hot-input" attrs="path, method, events, selector" >
<%
attributes['message'] ||= 'Loading...'
ajax_attrs, html_attrs = attributes.partition_hash(HoboRapidHelper::AJAX_ATTRS)
if @invalid_record && @this.new_record?
default_path = request.path + "/new"
else
default_path = request.path
end
add_data_rapid!(html_attrs, "hot-input", :ajax_attrs => ajax_attrs, :path => path || default_path, :method => method || 'GET', :events => events || 'change', :selector => selector)
%>
<span class="hot-input" param="default" merge-attrs="&html_attrs">
<input merge param />
</span>
</extend>

On Tuesday, August 18, 2009 at 9:49:04 AM UTC-7, Bryan Larsen wrote:
Reply all
Reply to author
Forward
0 new messages