Ruby on Rails Thursday, April 25, 2013

Hello all,

I am using a jquery plugin to search content on a page and highlight
keywords. The function call looks like this:

<script type="text/javascript">
$('div').highlight('@found');
</script>

I want the user to be able to assign the variable @found through an
input field. It seems like it should be fairly easy but I am new to
rails and have difficulty trying to make this work.

So far I have tried to create a method in the controller such as:

def found
@found = ""
#I've also tried @found = gets.chomp but that looks funny in rails
end

and then create the input field like such:


<%= form_tag do %>
<%= text_field :found, :found %>
<%= submit_tag("Post") %>
<% end %>

The page looks fine but it does not assign the variable.

If I try
<%= form_tag(@found) do %>
<%= f.text_field :found %>
<%= f.submit_tag("Post") %>
<% end %>

I get errors.

I may be going about this the wrong way. Any advice would be great.
Thanks

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment