Hola lista, estoy empezando en ruby haciendo pruebecillas y tocando
todo, me he leido el manual de
http://www.sobrerailes.com/pages/en_marcha_con_rails, estaba ahora
haciendo unos ejemplos en ajax y tenía una dudilla sobre un método del
manual que me estoy leyendo, el observe_field:
Resulta que en mi plantilla tengo:
|<label for="searchtext">Live Search:</label>
<%= text_field_tag :searchtext %>
<%= observe_field(:searchtext,
:frequency => 0.25,
:update => :search_hits,
:url => { :action => :live_search }) %>
<p>Search Results:</p>
<div id="search_hits"></div>|
En mi controlador puedo hacer?:
def live_search
render_text "El valor que me está llegando es: " + params[:searchtext]
end
En el momento que cambie el valor que tengo en la caja de texto hace la
llamada a ajax, llama al método "live_search", pero por qué me llega
vacío params[:searchtext]??
Otra duda, es una cosa absurda, solo para probar a que me devuelva el
HTML, si hago un link "Clickea aquí para buscar", éste me llamaría a un
método, me sustituiría ese link por la plantilla incluyendo el <%=
observer_field (.........) %> :
|<label for="searchtext">Live Search:</label>
<%= text_field_tag :searchtext %>
<%= observe_field(:searchtext,
:frequency => 0.25,
:update => :search_hits,
:url => { :action => :live_search }) %>
<p>Search Results:</p>
<div id="search_hits"></div>
|para que me funcionara cuando se insertara todo, se puede meter todo en una variable para que lo devuelva?
Bueno, de momento era esta duda, como estoy empezando voy a tener que
daros mucho la paliza :P, de momento me está encantando todo, adios al PHP
y bienvenido ruby.
Un saludo a todos, espero colaborar yo también cuando sepa bastante :P, de
momento iré a la conferencia del 24,25 de Noviembre para empaparme todo lo
que pueda.
|
|
on 2006-11-20 17:37
on 2009-12-23 10:49
You need to make a ajax request to the server with the selected id from your html page. you need to define a callback in the Ajax request for success and then populate the required fields. In the server retrieve the related results and render the format.js in the controller. I think if you to Agile Web Development book and see how ajax is handled.. You should be able to do this. Regards, Naren On Wed, Dec 16, 2009 at 9:13 PM, INDRANIL MUKHERJEE < indranil.since87@gmail.com> wrote: > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
on 2010-01-07 16:59
nada de complicaciones al pan pany al vino vino.
solo hay que agregarle esto:
:with => :searchtext,
<label for="searchtext">Live Search:</label>
<%= text_field_tag :searchtext %>
<%= observe_field(:searchtext,
:frequency => 0.25,
:update => :search_hits,
:with => :searchtext,
:url => { :action => :live_search }) %>
<p>Search Results:</p>
<div id="search_hits"></div>
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.