Rails Search Form -


i'm creating application tracks users , achievements (think, xbox live, etc.) these tables linked via join table. have search form on index lets users type in users name , new page loaded list of achievements user has earned. i'm not entirely sure how set search form, on index, search user table , return results on new page. appreciated. if require more information i'll happy provide it.

here's bit of skeleton code started based off think need have said. hope useful.

for search bit in index view:

<%= form_for user.new, :url => "search" |f| %>   <%= f.label :name %>   <%- f.text_field :name %> <%- end %> 

in controller:

def search   q = params[:user][:name]   @users = user.find(:all, :conditions => ["name %?%",q]) end 

and in search view:

<%-@users.each |user| %>   name: <%=user.name %>    <%- user.achievements.each |achievement| %>     <%= achievement.name %>   <%- end %> <%- end %> 

you would, of course, need ensure users , achievement models correctly linked:

class user << activerecord::base   has_many :achievements  end 

Comments

Popular posts from this blog

sql - text truncated using perl DBI insert -

c++ - Is it possible to compile a VST on linux? -

php - Pass object by reference or value -