# Re-rendering layout with form\_remote\_tag

**URL:** <https://www.ruby-forum.com/t/re-rendering-layout-with-form-remote-tag/86338>\
**Category:** Rails\
**Created:** [February 21, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/re-rendering-layout-with-form-remote-tag/86338 "2007-02-21T16:27:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [February 21, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/re-rendering-layout-with-form-remote-tag/86338/1 "2007-02-21T16:27:28Z")

</div>

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. &nbsp; 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!

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [February 21, 2007, 4:56pm UTC](https://www.ruby-forum.com/t/re-rendering-layout-with-form-remote-tag/86338/2 "2007-02-21T16:56:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [February 21, 2007, 5:14pm UTC](https://www.ruby-forum.com/t/re-rendering-layout-with-form-remote-tag/86338/3 "2007-02-21T17:14:30Z")

</div>

> you can render :layout =\> false

Yes, that did it.

Thanks so much!
