Not too familiar with paginate, but couple of suggestions:
-- Your :conditions syntax is wrong -- at the moment it will send the
query "WHERE status_id <
params[''candidates_status_id'']", not the "WHERE
status_id < 5", for example, that you want. You need to tell ruby to
convert the params to its value using #{}, or better still using the ?
syntax to substitute the variable like this: :conditions => ["status_id
< ?", params[:candidates_status_id]]
Check out the API docs on CRUD for find and how to use :conditions in
RoR (http://api.rubyonrails.org/classes/ActiveRecord/Base.html)
-- I think the params is wrong at the moment --more idiomatic use is
with a symbol (:symbol instead of ''string''), and I think the
select
statement is prob returning the status in
params[:candidates][:status_id]. Alternatively you could re-write the
select statement to return params[:status_id].
Something (off the top of my head) like:
select_tag("status_id",
options_from_collection_for_select(@statuses, "id", "name"))
This dries up the whole thing in one line.
-- In the view you also need to wrap up the select in a form tag to show
the action to perform (in this case list, again)
-- In the controller, you can clean things up quite a bit:
def list
@statuses = Status.find_all
status = params[:status_id] || 9 # Set to be status_id if it''s not
nil, otherwise 9
candidate_pages, @candidates = paginate :candidate, :per_page => 25,
:order =>
"firstname",
:conditions =>
["status_id < ?", status]
end
-- In things like this always check your logs -- it will show the query
being passed to the db -- you can see if it''s doing what you want.
HTH
Nina Ye wrote:>
> Hi,
>
>
>
> I''m new to Rails. I''m building a candidates tracking
system for
> recruiting. I have a List page, but instead of listing every
> candidate, I only wanted to list the candidates in certain statuses.
> The first time List page is hit, by default, it lists candidates in
> status < 9. But on the List page, there is a dropdown where all the
> statuses are listed, so that when user chooses a status, and hit Go
> Button next to the dropdown list, the List page would refresh with
> only candidates in that selected status.
>
>
>
> Simple enough scenario, but I just couldn''t get it. Every time I
> select anything in the dropdown and hit Go Button, I still get the
> list with three status < 9
>
>
>
> Here is my code in List.rhtml.
>
>
>
> Show Candidates: <select id="candidates_status_id"
> name="candidates[status_id]">
>
> <option value="" selected="selected" >Active in
process</option>
>
> <% @statuses = Status.find(:all, :order => "id")
>
> @statuses.each do |item| %>
>
> <option value="<%= item.id %>"><%= item.name
%></option>
>
> <% end %>
>
> </select><input name="commit" type="submit"
value="Go" />
>
>
>
> In the controller, I have
>
>
>
> def list
>
> if params[''candidates_status_id''] == nil then
>
> @candidate_pages, @candidates = paginate :candidate,
> :per_page => 25,
>
> :order => "firstname",
>
> :conditions => "status_id < 9"
>
> @statuses = Status.find_all
>
> else
>
> @candidate_pages, @candidates = paginate :candidate,
> :per_page => 25,
>
> :order => "firstname",
>
> :conditions => "status_id <
> params[''candidates_status_id'']"
>
> @statuses = Status.find_all
>
> end
>
>
>
> end
>
>
>
> Any suggestion is appreciated.
>
> Nina Ye
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060705/48f37b0f/attachment.html