
Adding groups from a form
Reported by Josh | December 26th, 2008 @ 06:08 PM
I'm trying to create a form that lets the user search multiple fields in an association I tried using groups but can't get them to work in the form:
User has_many :games
(user.games.name = 'tictactoe' AND user.games.fun = 'yes') OR (user.games.name = 'checkers' AND user.games.fun = 'yes') OR (user.games.name = 'chess' AND user.games.fun = 'no')
is there an easy way to do this from a form and dropdowns?
Thanks,
.....Josh.....
Comments and changes to this ticket
-
Ben Johnson December 27th, 2008 @ 12:32 PM
- State changed from new to resolved
Take a look at my blog post or the documentation in the library:
-
Josh December 28th, 2008 @ 05:18 PM
Thanks, but I tried that and it didn't work:
my controller: @search = Player.new_search(params[:search]) @search.conditions.is_no_call = 0 if params[:search].nil? # default if no params are passed in @players, @players_count = @search.all, @search.count
my view: <% form_for @search do |f| %>
<% f.fields_for "conditions" do |conditions_array| %>
<% conditions_array.fields_for "[]", f.object.conditions do |players| %>
<%= players.label :firstname_keywords, "First Name" %> <%= players.text_field :firstname_keywords %>
gets rendered like this:
<label for="search_conditions_____firstname_keywords">First Name</label> <input id="search_conditions_____firstname_keywords"
name="search[conditions][[]][firstname_keywords]" size="30" type="text">
<label for="search_conditions_____lastname_keywords">Last Name</label> <input id="search_conditions_____lastname_keywords"
name="search[conditions][[]][lastname_keywords]" size="30" type="text">
Because of this "[conditions][[]]" the conditions don't come through on the param: Parameters: {"commit"=>"Search", "search"=>{"conditions"=>{}, "order_as"=>"", "priority_order_by"=>"", "per_page"=>"25", "order_by"=>"", "priority_order_as"=>""}, "action"=>"index", "controller"=>"players"}
ruby script/about ActiveSearch: Ferret is not available on this system About your application's environment Ruby version 1.8.6 (powerpc-darwin8.11.0) RubyGems version 1.2.0 Rails version 2.1.2 Active Record version 2.1.2 Action Pack version 2.1.2 Active Resource version 2.1.2 Action Mailer version 2.1.2 Active Support version 2.1.2
I'm using searchlogic 1.6.3
Thanks,
.....Josh.....
-
Josh December 28th, 2008 @ 05:27 PM
Thanks, but I tried that and it didn't work:
my controller: @@@@search = Player.new_search(params[:search]) @search.conditions.is_no_call = 0 if params[:search].nil? # default if no params are passed in @players, @players_count = @search.all, @search.count@@@
my view: @@@<% form_for @search do |f| %>
<% f.fields_for "conditions" do |conditions_array| %>
<% conditions_array.fields_for "[]", f.object.conditions do |players| %>
<%= players.label :firstname_keywords, "First Name" %> <%= players.text_field :firstname_keywords %>@@@
gets rendered like this:
@@@
<label for="search_conditions_____firstname_keywords">First Name</label> <input id="search_conditions_____firstname_keywords"
name="search[conditions][[]][firstname_keywords]" size="30" type="text">
<label for="search_conditions_____lastname_keywords">Last Name</label> <input id="search_conditions_____lastname_keywords"
name="search[conditions][[]][lastname_keywords]" size="30" type="text">@@@
Because of this "[conditions][[]]" the conditions don't come through on the param: @@@Parameters: {"commit"=>"Search", "search"=>{"conditions"=>{}, "order_as"=>"", "priority_order_by"=>"", "per_page"=>"25", "order_by"=>"", "priority_order_as"=>""}, "action"=>"index", "controller"=>"players"}@@@
ruby script/about @@@ActiveSearch: Ferret is not available on this system About your application's environment Ruby version 1.8.6 (powerpc-darwin8.11.0) RubyGems version 1.2.0 Rails version 2.1.2 Active Record version 2.1.2 Action Pack version 2.1.2 Active Resource version 2.1.2 Action Mailer version 2.1.2 Active Support version 2.1.2@@@
I'm using searchlogic 1.6.3
Thanks,
.....Josh.....
-
Josh December 28th, 2008 @ 05:34 PM
Thanks, but I tried that and it didn't work:
Sorry, trying to get the formatting right :)
my controller: @@@ruby @search = Player.new_search(params[:search]) @search.conditions.is_no_call = 0 if params[:search].nil? # default if no params are passed in @players, @players_count = @search.all, @search.count
my view: @@@ruby <% form_for @search do |f| %> <% f.fields_for "conditions" do |conditions_array| %> <% conditions_array.fields_for "[]", f.object.conditions do |players| %> <%= players.label :firstname_keywords, "First Name" %> <%= players.text_field :firstname_keywords %>
gets rendered like this:
@@@ruby
<label for="search_conditions_____firstname_keywords">First Name</label> <input id="search_conditions_____firstname_keywords"
name="search[conditions][[]][firstname_keywords]" size="30" type="text">
<label for="search_conditions_____lastname_keywords">Last Name</label> <input id="search_conditions_____lastname_keywords"
name="search[conditions][[]][lastname_keywords]" size="30" type="text">
Because of this "[conditions][[]]" the conditions don't come through on the param: @@@ruby Parameters: {"commit"=>"Search", "search"=>{"conditions"=>{}, "order_as"=>"", "priority_order_by"=>"", "per_page"=>"25", "order_by"=>"", "priority_order_as"=>""}, "action"=>"index", "controller"=>"players"}
ruby script/about
ActiveSearch: Ferret is not available on this system About your application's environment Ruby version 1.8.6 (powerpc-darwin8.11.0) RubyGems version 1.2.0 Rails version 2.1.2 Active Record version 2.1.2 Action Pack version 2.1.2 Active Resource version 2.1.2 Action Mailer version 2.1.2 Active Support version 2.1.2
I'm using searchlogic 1.6.3
Thanks,
.....Josh.....
-
Josh December 28th, 2008 @ 09:20 PM
It didn't work in Rails 2.1.2 or 2.2.2
This does work though: form_for @search do |f| fields_for "conditions", :index => '' do |ff| %>
There is a bug in the searchlogic code that doesn't allow conditions to be an array:
lib/searchlogic/conditions/protection.rb: conditions.is_a?(Hash) shoud be conditions.is_a?(Hash) || conditions.is_a?(Array)
There is a bug in Rails 2.2.2 where date_select doesn't work, but I'm working on a patch and when I finish, I'll put a link here.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Provides common named scopes and object based searching.