Strange application.rhtml rendering

Hello,

I’m trying to set up my global layout (application.rhtml) and have
followed a simple XHTML set up with the <%= yield%> for content. My
application.rhtml starts off with <!DOCTYPE … etc. But when I look at
a view that should be using this layout in a browser, I see (in
Firefox), ?? ?<?!?D?O?C?T?Y?P?E? … etc. all throughout the entire
file. I tried erasing all content from the file and still ended up with
two ?s being displayed. IE7 doesn’t show this (it shows the expected
markup, but does not show the content that should be placed in the
‘yield’ section. It doesn’t seem to be a problem with the view
understanding what layout to use, as I’m seeing the layout (sort of).
Any ideas?

Thanks,

Tony

Hi Tony,

Tony T. wrote:

Any ideas?
For us to help you, you’re going to need to show us some code.

Best regards,
Bill

For us to help you, you’re going to need to show us some code.

Thanks so much for your reply.
Here’s the code and output (3 sections) that I described in the earlier
post:

(1)The view:
\app\views\roster_team\index.rhtml

<%a = RosterTeam.find_by_season(1, :conditions => ['nameCodeTeam = ?','MEXI'])%> <%="Team code name = " + a.nameCodeTeam%>
<%="Team season = " + a.season.to_s%>
<%="Team updated = " + a.updated.to_s%>


<%b = RosterTeam.find_by_season(1, :conditions => ['nameCodeTeam = ?','USAM'])%> <%="Team code name = " + b.nameCodeTeam%>
<%="Team season = " + b.season.to_s%>
<%="Team updated = " + b.updated.to_s%>

(2)The layout:
\app\views\layouts\application.rhtml

Test

Some sort of header line will go here with dropdown options.

<%=yield%>

Some sort of footer line may go here with who knows what.

(3) The output (in Firefox - basically the layout with ? everywhere):
http://localhost:3000/roster_team/

��<�!�D�O�C�T�Y�P�E� �h�t�m�l� �P�U�B�L�I�C� �"�-�/�/�W�3�C�/�/�D�T�D�
�X�H�T�M�L� �1�.�0� �S�t�r�i�c�t�/�/�E�N�"�
�"�h�t�t�p�:�/�/�w�w�w�.�w�3�.�o�r�g�/�T�R�/�x�h�t�m�l�1�/�D�T�D�/�x�h�t�m�l�1�-�s�t�r�i�c�t�.�d�t�d�"�>�
� �<�h�t�m�l�
�x�m�l�n�s�=�"�h�t�t�p�:�/�/�w�w�w�.�w�3�.�o�r�g�/�1�9�9�9�/�x�h�t�m�l�"�
�x�m�l�:�l�a�n�g�=�"�e�n�"� �l�a�n�g�=�"�e�n�"�>� � �<�h�e�a�d�>� � � �
� � � � �<�m�e�t�a� �h�t�t�p�-�e�q�u�i�v�=�"�C�o�n�t�e�n�t�-�t�y�p�e�"�
�c�o�n�t�e�n�t�=�"�t�e�x�t�/�h�t�m�l�;� �c�h�a�r�s�e�t�=�u�t�f�-�8�"�
�/�>� � � � � � � � �<�t�i�t�l�e�>�T�e�s�t�<�/�t�i�t�l�e�>� � � � � � �
� �<�l�i�n�k� �t�y�p�e�=�"�t�e�x�t�/�c�s�s�"�
�r�e�l�=�"�s�t�y�l�e�s�h�e�e�t�"�
�h�r�e�f�=�"�/�p�u�b�l�i�c�/�s�t�y�l�e�s�h�e�e�t�s�/�m�a�i�n�.�c�s�s�"�
�/�>� � �<�/�h�e�a�d�>� � �<�b�o�d�y�>� � � � � � � � � �<�d�i�v�
�i�d�=�"�g�l�o�b�a�l�L�a�y�o�u�t�"�>� � � � � � � � � �<�h�3�>�S�o�m�e�
�s�o�r�t� �o�f� �h�e�a�d�e�r� �l�i�n�e� �w�i�l�l� �g�o� �h�e�r�e�
�w�i�t�h� �d�r�o�p�d�o�w�n� �o�p�t�i�o�n�s�.�<�/�h�3�>� � � � � � � � �
�<�%�=�y�i�e�l�d�%�>� � � � � � � � � �<�h�3�>�S�o�m�e� �s�o�r�t� �o�f�
�f�o�o�t�e�r� �l�i�n�e� �m�a�y� �g�o� �h�e�r�e� �w�i�t�h� �w�h�o�
�k�n�o�w�s� �w�h�a�t�.�<�/�h�3�>� � � � � � � � � �<�/�d�i�v�>� �
�<�/�b�o�d�y�>� � �<�/�h�t�m�l�>�

Hi Tony,

Tony T. wrote:

It does appear from what’s being rendered that there could be something
wrong with application.rhtml, but nothing jumps out at me. Have you
looked
at the page source to see what’s being rendered? Your view, on the
other
hand …

(1)The view:
\app\views\roster_team\index.rhtml

<%a = RosterTeam.find_by_season(1, :conditions => ['nameCodeTeam = ?','MEXI'])%>

This find should be moved into your controller section and the result
assigned to an instance variable (e.g., @a) which can be used here. I
have
a sneaking suspicion that your choice of ‘a’ as a variable name may be
part
of the problem too. Rails’ rendering engine logic may be having trouble
with ‘<%a’, potentially mixing it with processing for ‘<a’. Just a
guess,
but changing it would be easy and might yield some different results.
Also,
you can use more than one condition in your find_by_ . At any rate, in
your
controller I’d suggest something like…

@teama= RosterTeam.find_by_season_and_nameCodeTeam(1, ‘MEXT’)

<%="Team code name = " + a.nameCodeTeam%>

If your intent here is to print out the “Team season =” and then the
value
of a.season, use
Teams season = <%= @teama.season.to_s %>
Anything the Rails finds in your views or layouts that’s not inside <%=
%>
or <% %> simply gets passed through. Same comment for the other lines
here.

Same pattern for team b. I’m not sure why you’re doing two separate
finds,
rather than one find with an ‘or’ condition on the name, but that’s a
different question. Your finds should be in your controller with the
results assigned to instance variables.

Key to solving your problem, I think, is a quick look at the page souce
being generated. If the problem’s in application.rhtml like you think,
some
or all of the tags that appear in that file will be screwed up. If it’s
in
your view file, then those tags will be fine and the content inside your
globalLayout div will show problems.

hth,
Bill

try to save “\app\views\layouts\application.rhtml” with the encode
“UTF-8”,
you may be saving as “Unicode”.
sorry, my english is not very good. -_-.

2007/4/6, Tony T. [email protected]:

you may be saving as “Unicode”.

Jimmy, that was the issue - thank you. I have been getting my feet wet
with RoR and was trying to use a freeware editor called ConTEXT, which
apparently has no ability to save as UTF-8 (or at least the
functionality is not readily apparent to me). I popped the
application.rhtml file into Notepad and now all is blissful.

Bill, thanks for digging into the question further than the immediate
issue. It’s very helpful to get tips from experienced users. Any
recommendations on a good editor for RoR (on the fee scale of free to
relatively cheap)?

Thanks again,

Tony

Hi Jimmy,

Jimmy Kuu wrote:

try to save “\app\views\layouts\application.rhtml” with
the encode “UTF-8”, you may be saving as “Unicode”.

I just saw your response to Tony and wish I’d seen it before my reply (I
really need to get a threaded email client for lists). Good guess.
Better
than mine, I think. It didn’t occur to me.

Best regards,
Bill

Hi Tony,

Tony T. wrote:

Bill, thanks for digging into the question further than the immediate
issue. It’s very helpful to get tips from experienced users. Any
recommendations on a good editor for RoR (on the fee scale of free to
relatively cheap)?

You’re welcome. The problem/solution Jimmy identified didn’t occur to
me.
Never run into it myself, but now I’ll know to watch out for it.

I use TextPad for a Windows editor (
TextPad downloads ). It’s a free trial that,
past
the trial period, throws up a dialog asking if you’re ready to buy or
want
to continue evaluation. You don’t have to ever buy, but it’s only $32
US if
you want to. You might also want to try out Scite (
Scintilla and SciTE ) which is straight freeware and
also
runs on Redhat Linux. It’s included as part of the Instant Rails
distribution. There are others, of course, but those are the ones I’m
most
familiar with.

hth,
Bill

Another nice windows editor – similar to TextPad, but free - is
notepad++:

http://notepad-plus.sourceforge.net/uk/site.htm

b