Im in love with meta_search, a great gem but i have a question: when
using it in controllers wich has the same name as the model (Photo =>
PhotosController) it workes like a charm. But i have a
PeoplesController for handling accounts, profiles etc - and if i try
to use it there i get an error of:
NoMethodError in Peoples#index
Showing /index.html.erb where line #33 raised:
undefined method `screen_name_contains' for #<ActiveRecord::Relation:
0x10676f2a8>
Controller:
def index
@search = Account.search(params[:search])
@users = @search.where(:status =>
"active").page(params[:page]).per(24)
end
If you still have trouble, probably easiest is post your current meta search code and the models you are trying to associate, and their associated schema (fields).
I think i have mislead you with the subject line of this post.
Its not that Peoples are a releation of Accounts. Peoples are just a
Controller
to move the viewing parts account from AccountController. So the
problem is not how to do a
relation between two models; i need to get meta_search understand that
it should search the
Account (and then models associated to Account). I think i get the
error because it cant find
any model to search (which is correct; people doesn't exists.
class PeoplesController < ApplicationController
def index
@search = Account.search(params[:search])
@users = @search.where(:status =>
"active").page(params[:page]).per(24)
end
end
class Account < ActiveRecord::Base
....
# screen_name :string(255)
....
end
But this gets me:
NoMethodError in Peoples#index
Showing /Users/niklasnson/mugcube_app/mugcube/app/views/peoples/
index.html.erb where line #31 raised:
undefined method `screen_name_contains' for #<ActiveRecord::Relation:
0x107346c48>
The other two models/controllers i have been using was both the same
(photo and PhotoController and casting and CastingController) so i
thought that
the error was in that Account was the model and then a
PeoplesController. But after your last message i think this should not
matter ?
So I am assuming your Account model has a screen_name attribute, correct?
Can you post here the params which your controller is receiving when you post this form? I am assuming that there is probably some conflict in the params where you might have something like params[:people][:screen_name]… and of course metasearch is not going to find it… you will need to make the input params to be what meta search would expect… and ideally make your form based on the account model like:
@account = Account.new # just used for the search
form_for @account
f.text_field :screen_name
…
Otherwise you can do what I have done in the past which is to create a form however you want and then marry the params to metasearch in the model. But I would not recommend this until you understand what is going on.
I get the error
NoMethodError in Peoples#index
Showing /Users/niklasnson/mugcube_app/mugcube/app/views/peoples/
index.html.erb where line #32 raised:
undefined method `screen_name_contains' for #<Account:0x1066e2ab0>
Directly when i try to acccess the page so i cant post the form.
Tryed
<% @account = Account.new # just used for the search %>
<% simple_form_for(:search, @account, :html => {:method => :get}) do |
f> -%>
<%= f.input :screen_name_contains %>
<%= f.button :submit %>
<% end -%>
Again please copy the params from the server console on the post. Also, try using account_screen_name_contains… maybe.
One other idea is to simplify, so start in the account controller and model and do a simple search following exactly the code on the metasearch github. Once you get that working right get more creative, and go for what you are trying. In the end this will save you time and at least you get on the right path.