radio buttons form in ruby on rails

572 views
Skip to first unread message

@ddy

unread,
Jun 15, 2013, 7:50:37 AM6/15/13
to rubyonra...@googlegroups.com
Hi there!

I m using this form:

<%= form_for(:usage, :url=> {:action =>'getResults'}) do |f| %>
    <legend>Select search criteria : </legend>    
    
    <%= f.radio_button :filter, 'uni'%> <span style="font-size:15px;">For Unicast only</span>
    <br>
    <%= f.radio_button :filter, 'multi' %> <span style="font-size:15px;">For Multicasts only</span>
    <br>
    <%= f.radio_button :filter, 'month' %> <span style="font-size:15px;">Current Month</span>
    <br>
    <%= f.radio_button :filter, 'date' %> <span style="font-size:15px;">On this date:
    <br><br>
    <%= f.date_select(:date,:order=>[:day,:month,:year])%>
    <br>
    <%= link_to 'Search', {:action=>"getResults"}, :remote => true, :submit%>
    <% end %>


and in controller I have:
def getResults
if params[:filter] == 'uni'
     
     @results = Multicasts.where(:sms_voice => 'sms')
    end
     
    if params[:filter] =='multi'
      @results = Multicasts.where(:when => 'im')
    end
     
    if params[:filter] =='month'
       @results = Multicasts.where('extract(month  from datetime) = ?', MONTH(date))
    end

    render :new_results
end


Is this a correct way to read info from radio buttons.
Please help, it is not working. Is the syntax correct?

Hassan Schroeder

unread,
Jun 15, 2013, 11:45:39 AM6/15/13
to rubyonra...@googlegroups.com
On Sat, Jun 15, 2013 at 4:50 AM, @ddy <aditi24....@gmail.com> wrote:

> Is this a correct way to read info from radio buttons.
> Please help, it is not working. Is the syntax correct?

It's horrible markup and very un-Ruby/Rails-ish code, but the key
point is: what EXACTLY do you mean by "not working"?

Is your controller getting the params you expect or not? Is the value
of @results not what you expect for a given input?

What is the problem?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Reply all
Reply to author
Forward
0 new messages