I have a calendar that I''m trying to update via ajax: A user selects a
different month, clicks the submit button, and the calendar shows the
month they selected without reloading the whole page.
Now, my problem is that it is rendering the layout multiple times. I''m
getting cascading menus, images, etc.
Here''s my controller code:
def dyna_calendar
#get either current month or requested month
if not request.post?
@selected_date = Date.today
@year = Time.now.year
@month = Time.now.month
else
@selected_date = Date.new(params[:date][:year].to_i,
params[:date][:month].to_i, Time.now.mday)
@year = Date.new(params[:date][:year].to_i, Time.now.month,
Time.now.mday).year
@month = Date.new(Time.now.year,params[:date][:month].to_i,
Time.now.mday).month
end
@sales_orders = SalesOrder.find(:all,
:conditions =>
[''month(ship_date) ? and year(ship_date) = ?'',@month,@year])
render :partial => ''calendar_header'', :layout =>
''standard''
end
And here is the content of _calendar_header:
<div id=''ajax_cal''>
<h2>Ship Date Calendar</h2>
<table class="list_header"><tr><td>
<% form_remote_tag(:update => ''ajax_cal'', :url =>
{:action =>
''dyna_calendar''}) do -%>
<%= select_month(@selected_date)%>
<%= select_year(@selected_date)%>
<%= submit_tag ''Go'' %>
<% end -%></td>
<td>
<%= ''<b>'' + @sales_orders.length.to_s +
''</b> total orders this
month. Total: <b>'' + sprintf("%#1.2f",
@sales_orders.sum(&:amount)) + ''</b>''%>
</td>
</tr></table>
<%calendar({:year => @year, :month => @month, :abbrev => (0..0)}) do
|d|
cell_text = "#{d.mday}<br />"
cell_attrs = {:class => ''day''}
@sales_orders.each do |o|
if (d.mday == Time.now.mday and d.month == Time.now.month)
cell_attrs[:style] = ''background: #ff9;''
end
if (o.ship_date.month == d.month and o.ship_date.mday == d.mday )
cell_text << link_to( o.id.to_s, :controller =>
''sales_orders'', :action => ''show'',
:id => o ) << ''<br
/><span
class="cal_text">'' +truncate(o.sold_to, 15) +
''<br />'' +
truncate(o.description,12) + ''<br />'' +
sprintf("%#1.2f", o.amount) +
"</span><br /><br />"
cell_attrs[:class] = ''specialDay''
end
end
[cell_text, cell_attrs]
end
%>
</div>
How can I render the layout only once, no matter how many times the user
changes the calendar month? I''m sure I''m missing something
easy here.
Thanks!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---