Forum: Ruby on Rails Using calendar helper to jump to other months

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.
Jason (Guest)
on 2007-02-14 03:14
Hello,

I have the following in my controller to display a calendar using
calendar helper:

    if not request.post?
      @year = Time.now.year
      @month = Time.now.month
    else
      @year = Date.new(params[:date][:year], Time.now.month.to_s,
Time.now.mday.to_s).year    # this is line 154
      @month = Date.new(Time.now.year.to_s,params[:date][:month],
Time.now.mday.to_s).month
    end


This is what I have in the corresponding view:

<h1>Ship Calendar</h1>


<%= start_form_tag %>
<%= select_month(Date.today)%>
<%= select_year(Date.today)%>
<%= submit_tag 'Go' %>
<%= end_form_tag %>

<%=
calendar({:year => @year, :month => @month}) do |d|
  cell_text = "#{d.mday}<br />"
  cell_attrs = {:class => 'day'}

  @sales_orders.each do |o|
    if o.ship_date.month == d.month
        if o.ship_date.mday == d.mday

          cell_text << link_to( o.id.to_s, :controller =>
'sales_orders', :action => 'show', :id => o ) << "<br />"
          cell_attrs[:class] = 'specialDay'
        end
    end
  end
  [cell_text, cell_attrs]
end
%>


I can view the calendar initially, since it defaults to the current
month.  But when I change the select box's month and submit it, I get
the following error:

comparison of String with 0 failed
#{RAILS_ROOT}/app/controllers/histories_controller.rb:154:in
`history_calendar'

What am I doing wrong?  I'm just trying to be able to switch to
different months for the calendar.

Thanks,

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