Re-rendering layout with form_remote_tag


#1

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:

Ship Date Calendar

<% form_remote_tag(:update => 'ajax_cal', :url => {:action => 'dyna_calendar'}) do -%> <%= select_month(@selected_date)%> <%= select_year(@selected_date)%> <%= submit_tag 'Go' %> <% end -%> <%= '' + @sales_orders.length.to_s + ' total orders this month.   Total: ' + sprintf("%#1.2f", @sales_orders.sum(&:amount)) + ''%>

<%=
calendar({:year => @year, :month => @month, :abbrev => (0…0)}) do |d|
cell_text = “#{d.mday}

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 ) << ‘
’ +truncate(o.sold_to, 15) + ‘
’ +
truncate(o.description,12) + ‘
’ + sprintf("%#1.2f", o.amount) +



cell_attrs[:class] = ‘specialDay’
end
end
[cell_text, cell_attrs]
end
%>

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!


#2

On 21-Feb-07, at 10:27 AM, Jason wrote:

Here’s my controller code:
@year = Date.new(params[:date][:year].to_i, Time.now.month,
render :partial => ‘calendar_header’, :layout => ‘standard’

end

you can render :layout => false

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!

does that help?
J


#3

you can render :layout => false

Yes, that did it.

Thanks so much!