On Aug 25, 2010, at 8:29 PM, Mark Sobkowicz wrote:

I have two models - an assignment has_many responses, and on the assignment show page there is a form to add a response. When you add a response you are sent to a show page for the response, which is not what I want. I want the assignment page to reload showing the new response. I tried to do this with the tag <after-submit stay-here/>, but it doesn't work. Here is my form definition:

<extend tag="form" for="Response">
        <old-form merge>
                <error-messages param/>
                <p><input:body/></p>
<input id="response[user_id]" name="response[user_id]" type="hidden" value="&current_user.id" />
                <div param="actions">
                        <submit label="Save" param/><or-cancel param="cancel"/>
                </div>
                <after-submit stay-here/>
        </old-form>
</extend>

If I am on a page whose URL is:

http://localhost:3000/assignments/2-assignment-with-hidden-responses

the HTML shows the line

<input id="page_path" name="page_path" type="hidden" value="assignments/show" /> And when I click the add button, it tries to take me to /assignments/ show, which does not exist.

Suggestions for a solution or for a work-around?


Just to check, does that mean you're posting the form to an auto_action_for-type controller action? (/assignments/2/responses for your example)

Assuming so, the problem is that stay-here wasn't able to figure out where "here" was. page_path encodes the controller and action (I *believe* it's principally used by the parts mechanism - Tom, Bryan?) but not the record ID, so things get confused when the parts are used to construct a new URL (paraphrased from model_controller.rb):

redirect_to url_for(:controller => controller, :action => action)

Normally, the behavior of url_for is correct, and the ID value from the incoming request is used to construct the URL. In this case, however, you end up with the desired record id in params[:assignment_id] rather than in params[:id] where url_for will need it.

Some thoughts on how to get around this:

- specify the URL explicitly in after-submit: <after-submit uri="#{url_for(this_parent)}" /> (this may complicate things if you have other forms that edit/create Response objects that *aren't* posting to child actions)

- or, fake the Rails parameter parser out: in the Response controller, add this:

def create_for_assignment
  params[:id] = params[:assignment_id]
  hobo_new_for :assignment
end

Ultimately, this is a bug that should get fixed, as page_path is likely to be unhelpful in other situations.

--Matt Jones

--
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to