Topic: Very Very Strange!!! Ruby Problem

Hi people i have a very strange problem.

I am using a lifesearch function which you can place some text in.
Only When i get the Post in the Controller the variable gives me this

placedtext=     ... The equal sign gets placed at the end of the variable.(FFS)

This is My Livesearch code which is placed in the view.

<h1>Search:</h1>

&nbsp;<%= text_field_tag :searchtext %>

<%= observe_field(:searchtext,
:frequency => 4.0,
:update => :search_hits,
:loading => " Element.show('spinner')",
:complete => "Element.hide('spinner')" ,
:url => { :controller => "domain", :action => "domain_search" }) %>

<div id="search_hits"></div>


This is the code that gets the post variable so i can do stuff with it.

@entered_text= request.raw_post || request.query_string (actually both give the same result)

When i do puts @entered_text ic for example nerd4life.nl= instead of just nerd4life.nl

Gsub did not work an split functions also do not remove the = sign...... :'(

I used this function before and stupid enough it did not do it like that(and i am sure it aint the drugs that i have been taking to ease the pain wink ).
The only difference is i work on a Imac instead of Windows XP but i guess thats not the problem aswel...... Hope someone can help me out, or i have to go back to a sumbit button again.

Greets

Vincent

Re: Very Very Strange!!! Ruby Problem

yeah i also have this problem.

Re: Very Very Strange!!! Ruby Problem

Try doing this for fetching the entered text:

@entered_text = params[:value]

If that doesn't work, take a look at the development log when the request is submitted to see what parameters are being sent. I believe "request.raw_post" is the old way to do it which isn't valid anymore.

Railscasts - Free Ruby on Rails Screencasts

Re: Very Very Strange!!! Ruby Problem

if i replace

@phrase = request.raw_post

with
@phrase = params[:searchQuery]

my form is
text_field_tag(:searchQuery)

I get


Processing CustomersController#search (for 127.0.0.1 at 2007-04-24 19:13:56) [POST]
  Session ID: 1d7fc61936bcbeda395ee206965d5b77
  Parameters: {"neil"=>"", "action"=>"search", "controller"=>"customers"}
  Customer Columns (0.002811)   SHOW FIELDS FROM customers
  SQL (0.000439)   SELECT count(*) AS count_all FROM customers WHERE (name like NULL)
  Customer Load (0.001253)   SELECT * FROM customers WHERE (name like NULL) LIMIT 0, 12


@phrase is not picking it up.
maybe text_field_tag is wrong ?

and also..

Parameters: {"neil"=>"",

does that mean its not assigning my search input "neil" to anything ?

Last edited by neilh (2007-04-24 13:30:37)

Re: Very Very Strange!!! Ruby Problem

Where does the "neil" parameter come in? That's not the name of the text field. Is there any othe field with that name? Perhaps the incorrect form is getting submitted?

Railscasts - Free Ruby on Rails Screencasts

Re: Very Very Strange!!! Ruby Problem

neil is the value being i typed in the search field

I dont see what is going wrong. But params[:searchQuery] is not picking it up.

observer.rhtml

Search: 
<%= text_field_tag :searchQuery %>

<%= observe_field(:searchQuery,
          :frequency  =>  0.5,
          :update     =>  :target_id,
          :url        =>  { :action => :search }) %>
             
<div id="target_id"></div>


controller
def search
  @phrase = params[:searchQuery]
end

search.rhtml
@phrase = <%=@phrase%>

if i type "neil" into the search box i get (development.log)

Parameters: {"neil"=>"", "action"=>"search", "controller"=>"customers"}

and @phrase is empty

Now i change my params[:searchQuery] to request.raw_post in the controller like such

def search
  @phrase = request.raw_post
end

i get (development.log)

  Parameters: {"neil"=>"", "action"=>"search", "controller"=>"customers"}

and @phrase = neil=

which is the trailing = problem from earlier

Re: Very Very Strange!!! Ruby Problem

Which version of Rails are you using? Also, how long ago was it that you generated this rails project? The Prototype and Scriptaculous files may be out of date. IIRC, this is how it used to behave. You may want to try generating a new blank rails project and copying over the "javascripts" files to your old project in order to update them.

Railscasts - Free Ruby on Rails Screencasts

Re: Very Very Strange!!! Ruby Problem

this is happening to me too. i'm on edge rails. it seems strange to me that the value in the text field become a key?

so i'm using 

request.raw_post.chop

to get rid of the =

Last edited by pleatherrebel (2007-04-27 14:03:33)