Saturday, October 07, 2006

I wanted to allow a user to type in the address for their community and then instantly inform them whether the address they wanted was available.

In my controller:

def check_portal_url
end


In my view:

<%@comm = Portal.find_by_portal_url(@params[:search]) %>
<%if @comm%>
<%=@params[:search]%> is taken, please try a different address.
<%else%>
<%=@params[:search]%> is available.
<%end%>


and in my form



<%= observe_field(:portal_portal_url,
:frequency => 0.5,
:update => :observe_results,
:loading => "Element.show('spinner')",
:complete => "Element.hide('spinner')",
:url => { :controller=>'ajax',:action => 'check_portal_url' },
:with => "'search=' + escape(value)"
) %>



<div id="observe_results"></div>
In the above, the
                :with => "'search=' + escape(value)"

part is very important as without it, the value of the field will be very hard to access.

0 Comments:

Post a Comment

<< Home

eXTReMe Tracker