Forum: Ruby on Rails progressive updates

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-19 04:20
(Received via mailing list)
I have a list view and have it sorting the data presented in the list
view by clicking on the top of the column - that works fine.

Now, I want to add a pop up-list which controls 3 different levels of
record select to be presented in this list...
- ALL
- placement.discharge_date IS NULL
- placement.discharge_date IS NOT NULL

I can have 3 different 'methods' and 'views' and switch between them
using and use render => :partial but what I am struggling with is
passing the selection from my pop-up list to the link_to tag.

<%= options = [[params[:vw], ""]] + Placement::VW_STRING
  select("", :vw, options) %>

<%= link_to 'Update',
  :action => 'list',
  :vw => params[:vw],
  :sort_by => params[:sort_by] %>

My problem is that what I select from the list doesn't change the
value :vw in the 'link_to'

How does one do this sort of thing?

Craig
6559f9b9607a89074ea5e238d31ffbc2?d=identicon&s=25 Kelly Felkins (Guest)
on 2006-02-22 03:11
(Received via mailing list)
Craig,

I'm not sure I understand what you are trying to do, but that's not
going to
stop me from trying to help!

I think I do the same thing you are attempting to do. I have a view of
things that are associated with people, and I sometimes filter them by a
single person. The people
are in a select list.

Here's the relevant view code:

<table>
<%= form_tag(:action => 'list', :id=>nil) %>
<tr><td>person filter: <%= select_tag(:pf,
options_for_select(people_list,
@selected_person)) %></td>
<td><%= submit_tag "update display" %></td></tr>
<%= end_form_tag %>
</table>

So there is an array of people and a selected person (@selected_person).
The
1st entry in the array is '-all-'

Then the *relevant* controller code looks like this:

  def list
    if params.include?(:pf)
      @session[:person_filter] = nil
      @session[:person_filter] = params[:pf] unless params[:pf].blank?
||
params[:pf]=='-all-'
    end
    if @request.post?
      options = {:action=>'list'}
      unless @session[:person_filter].blank?
        options[:filter] = 'who'
        options[:value] = @session[:person_filter]
      end
      redirect_to options
      return
    end

    @selected_person = nil
    unless @session[:person_filter].blank?
      options = add_conditions(options,
["who=?",@session[:person_filter]])
      @selected_person = @session[:person_filter]
    end
# a paginator
#  :
  end

So the html form parameter is "pf" and it gets set to a name or the
string
'-all-'.
I want it to be sticky and I want it to show up in the url. To
accomplish
these 2 things I put the parameter in the session as ":person_filter".
If I
get to the list via a post I redirect so that the url now contains the
person.

Before going to the list view I set the value @selected_person. The
select
list, ah, selects the currently selected person.

This is a little messy, but I like the way it works. It allows someone
to
filter the display, and then copy the url and send it to a buddy or
bookmark
it. But there must be an easier way.

-Kelly
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-02-22 04:38
(Received via mailing list)
On Tue, 2006-02-21 at 18:10 -0800, Kelly Felkins wrote:
> Here's the relevant view code:
> (@selected_person). The 1st entry in the array is '-all-'
>       options = {:action=>'list'}
>       options = add_conditions(options,
> accomplish these 2 things I put the parameter in the session as
> ":person_filter". If I get to the list via a post I redirect so that
> the url now contains the person.
>
> Before going to the list view I set the value @selected_person. The
> select list, ah, selects the currently selected person.
>
> This is a little messy, but I like the way it works. It allows someone
> to filter the display, and then copy the url and send it to a buddy or
> bookmark it. But there must be an easier way.
>
----
thanks Kelly - I don't know if you followed the track but Ezra has a
plug-in called ez_where which was precisely what I was looking for.

In case anyone is interested...I wanted to have this large find screen
with most of the columns in the table and allow a free form type of
search and the ez_where allowed me to easily 'AND' the search strings
that had data and discard the ones that didn't and I was even able to do
things like date ranges as part of the find too.

So I started with a 3 option view...All records, Current records or
'Filtered' where filtered represented the found set.

Then I put all of these results of the find into session variables which
allows me to retain them as the list view has column headers and
clicking the top of the column allows me to 're-order' the view, whether
it was All, Current or Filtered.

Thanks

Craig
This topic is locked and can not be replied to.