Hi all,
I’ve been trying to figure this out by myself and while I feel I’ve made
some progress, I feel kind of stuck. Let me see if I can explain what
I’m
trying to do. I have a very simple form with a text box and a text
area.
The text in each of these will eventually make it into a row in a table
in
my database. For now, the value in the text box represents a
del.icio.ustag. Currently, I figured out how to get an ajax observer
wired up so that
when the user enters a value into the text box and tabs away, my
controller
gets called along with the contents of the text box and the controller
then
makes a call to the delicious REST API and strips out bits of the return
and
renders them into the text area. This is all presently working, but I’m
still having some frustrations. I think I’m still missing a big chunk
of
understanding. Here’s what I’d like to do:
I’d like to just have a link_to_remote to call the action when the user
clicks a link, but I can’t for the life of me figure out how to read the
value out of the text box in that case without submitting the form.
Currently, the text box is created like so: <%= text_field_tag :tags %>
Originally, this was to be <%= text_field ‘query’, ‘tags’ %> so that the
value could be passed up to my Create method in the controller. I can
only
get my observer to work with the previous rhtml code.
Here’s the bulk of my code:
from the _form.rhtml partial:
Tags
<%= text_field_tag :tags %>
Results
<%= text_area 'query', 'results' %>
from the new.rhtml:
<%= form_remote_tag :action => ‘create’ %>
<%= render :partial => ‘form’ %>
<%= submit_tag “Create” %>
<%= end_form_tag %>
<%= observe_field(:tags,
:update => ‘query_results’,
:url => { :action => :get_results }) %>
Pertinent bits of the controller:
def get_results
render :update do |page|
@tags = request.raw_post
@results = “No Results”
...
CALL TO DELICIOUS using @tags
...
page['query_results'].value = @results
end
Can anyone spare a clue on how I can to a link_to_remote and pass the
value
of the text box and keep the textbox linked to the query object?
I realize the form_remote_tag is probably not necessary with the way I’m
doing things. I just noticed it - it’s an artifact of earlier, failed
attempts.
I’m still pretty darned new to both web development and RoR, so please
forgive me if I’ve just asked a bunch of stupid questions. I’m trying
to
learn.
I have the Agile Pragmatic book and if you can refer me to a section in
there, that would be great as would pointers to places to look in the
online
docs.
Thanks!!