Skip to content

Instantly share code, notes, and snippets.

@robertmilner
Created September 10, 2012 23:02
Show Gist options
  • Save robertmilner/3694600 to your computer and use it in GitHub Desktop.
Save robertmilner/3694600 to your computer and use it in GitHub Desktop.
Form with saved vairables
def index
if params[:commit] == 'Filter'
@title = params[:title]
title = @title.present? ? @title : nil
@type = params[:type]
type = @type.present? ? @type.gsub(/\s+/, '') : nil
@speaker = params[:speaker]
speaker = @speaker.present? ? @speaker : nil
@event_resource = params[:event_resource]
event_resource = @event_resource.present? ? @event_resource.to_i : nil
@date = params[:date]
date = @date.present? ? @date : nil
@start_time = params[:start_time]
start_time = @start_time.present? ? @start_time : nil
@duration = params[:duration]
duration = @duration.present? ? @duration : nil
@event_sessions = EventSession.for_event(current_event)
.title_has(title)
.speaker_has(speaker)
.of_type(type)
.on_day(date)
.lasting(duration)
.taking_place_at(event_resource)
# .speaker_has(speaker)
# .with_speaker(speaker)
#.with_status(params[:session_filter][:status])
else
@event_sessions = EventSession.for_event(current_event)
end
@types = EventSession::SESSION_TYPES.map { |type| type.titleize }
# @speakers = Attendance.for_event(current_event).speakers.map { |speaker| speaker.full_name }
@event_resources = current_event.event_resources
@dates = current_event.date_array
@start_times = EventSession.for_event(current_event).pluck(:starts_at).uniq.map { |t| t.strftime('%l:%M %p') }
@durations = EventSession.for_event(current_event).order(:duration).pluck(:duration).uniq
@event_sessions_count = @event_sessions
@event_sessions = @event_sessions.page(params[:page])
end
<%= form_tag('', method: 'get') do %>
<h2>Filters</h2>
<div class="row-fluid">
<div class="span4">
<label>The <strong>Session Title</strong> contains:</label>
<%= text_field_tag(:title, @title) %>
</div>
<div class="span4">
</div>
</div>
<div class="row-fluid">
<div class="span4">
<div class="select-margin">
<label>The <strong>Session Type</strong> is:</label>
<%= select_tag(:type, options_for_select(@types, @type), include_blank: true) %>
</div><!-- .select-margin -->
<div class="select-margin">
<label>The <strong>Date</strong> is:</label>
<%= select_tag(:date, options_for_select(@dates, @date), include_blank: true) %>
</div><!-- .select-margin -->
</div><!-- .span4 -->
<div class="span4">
<label>The <strong>Speaker Name</strong> contains:</label>
<%#= select_tag(:speaker, options_for_select(@speakers, @speaker), include_blank: true) %>
<%= text_field_tag(:speaker, @speaker) %>
<div class="select-margin">
<label>The <strong>Start Time</strong> is:</label>
<%= select_tag(:start_time, options_for_select(@start_times, @start_time), include_blank: true) %>
</div><!-- .select-margin -->
</div><!-- .span4 -->
<div class="span4">
<div class="select-margin">
<label>The <strong>Location</strong> is:</label>
<%= select_tag(:event_resource, options_from_collection_for_select(@event_resources, :id, :name, @event_resource), include_blank: true) %>
</div><!-- .select-margin -->
<div class="select-margin">
<label>The <strong>Duration</strong> is:</label>
<%= select_tag(:duration, options_for_select(@durations, @duration), include_blank: true) %>
</div><!-- .select-margin -->
</div><!-- .span4 -->
</div><!-- .row-fluid -->
<%= submit_tag 'Filter', class: 'btn btn-primary' %>
<%= link_to "Reset Filters", manage_event_sessions_path, class: 'btn' %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment