One more thing, you may want <form with="&nil" action="/concepts/new" updates="#welcome"><submit label="Update to new!"/></form>
That way your button won't disappear due to permissions checking... Bryan On Tue, Oct 30, 2012 at 4:33 PM, Ignacio Huerta <[email protected]> wrote: > Ohhh, thank you so much for the quick response, you really opened my eyes. I > tested your solutions and they work beautifully! > > Warm regards, > Ignacio > > El 30/10/12 20:22, Bryan Larsen escribió: > >> The problem is that using <a> for Ajax doesn't set params[:page_path]. >> If you use form ajax, that parameter automatically gets added. >> >> That was sort of deliberate. Take the example in the documentation. >> >> <a href="somewhere/else" update="body" push-state >> new-title="Somewhere else">Go somewhere else.</a> >> >> This would do the controller action for somewhere/else and render the >> "body" part from somewhere/else. >> >> If you did that via a form: >> >> <form action="somewhere/else" update="body"><submit label="Go >> somewhere else"/></form> >> >> it sets params[:page_path] to request.fullpath, so you get the >> controller action for somewhere/else and render the body from >> request.fullpath. >> >> That's generally the desired behaviour. <a> generally has a meaning >> of "go somewhere else", whereas an ajax form generally means "update >> the current page". >> >> So you could fix your problem by doing this: >> >> <a href="/concepts/new" params="&{:page_path => request.fullpath}" >> class="btn btn-primary" updates="#welcome">Update to new!</a> >> >> But really you should do this: >> >> <form action="/concepts/new" updates="#welcome"><submit >> label="Update to new!"/></form> >> >> Besides the page_path benefit, by putting it in a POSTable form, >> you're signalling that the operation is not idempotent. Among other >> things, this means that caches can't mess with it and that Google and >> other bots won't randomly follow it. >> >> Bryan >> >> >> On Tue, Oct 30, 2012 at 2:58 PM, Ignacio Huerta <[email protected]> >> wrote: >>> >>> I'm trying to make Ajax calls work the way I need them, and after some >>> trouble I've created a very small example to show my issue. The following >>> code works (the random number is updated): >>> >>> <h3 part="welcome"><%= rand.to_s %></h3> >>> <a href="/concepts" class="btn btn-primary" updates="#welcome">Update >>> to >>> index!</a> >>> >>> >>> But this code doesn't (Ajax returns error 500): >>> >>> <h3 part="welcome"><%= rand.to_s %></h3> >>> <a href="/concepts/new" class="btn btn-primary" >>> updates="#welcome">Update >>> to new!</a> >>> >>> Note: I have "hobo_ajax_response" in my new action in the >>> concepts_controller. >>> >>> The error as seen in Firebug is: >>> >>> undefined method `welcome_part' for >>> #<#<Class:0x00000003af2438>:0x00000005937510> >>> >>> I've been reading about part contexts in the Ajax manual and I've tried >>> playing with "@this" in the new action. I've also debugged a bit the >>> template_environment.rb file in the dryml gem, until: >>> send("#{context.part_name}_part", *context.locals) >>> >>> Does anyone know why "welcome_part" is accessible in the index action, >>> but >>> not in the new action? Is there any way to workaround this? >>> >>> Thanks! >>> >>> Regards, >>> Ignacio >>> >>> -- >>> Ignacio Huerta Arteche >>> http://www.ihuerta.net >>> Teléfono: 0034 645 70 77 35 >>> Email realizado con software libre >>> >>> -- >>> 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. >>> >> > > -- > Ignacio Huerta Arteche > http://www.ihuerta.net > Teléfono: 0034 645 70 77 35 > Email realizado con software libre > > -- > 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. > -- 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.
