Sunday 15 July 2012

Searching for words in Ruby on Rails -



Searching for words in Ruby on Rails -

my app lists words have been parsed database (sqlite). want add together search box rails application looks through dictionary of words , returns word searched in table format presented in view:

<% @words.each |word| %> <tr> <td><%= word.word %></td> <td><%= word.wordtype %></td> <td><%= word.description %></td> <td><%= link_to 'show', word %></td> </tr> <% end %>

i new rails , ruby help appreciated.

assuming want simple search (that doesn't allow misspellings allows partial spellings) create action (rename method name whatever want/need be):

def search # replace word model whatever model called @words = word.where('word "%?%"', params[:query]) end

note action should used method. subsequently, don't need utilize strongparameters.

ruby-on-rails ruby

No comments:

Post a Comment