2008/11/26 Bharat <[EMAIL PROTECTED]>:
> 3. How do you show inline Javascript code in a haml file? For
> example, the above new.html.erb file contains the following code:
> <script type='text/javascript'>
> $(document).ready(function() {
> show_openid = function() {
> $('#openid').show();
> $('#standard').hide();
> $('#openid_link').hide();
> $('#standard_link').show();
> createCookie('use_openid', 1, 30);
> $('#openid_url').value = 'http://';
> }
You could use the :javascript filter
:javascript
$(document).ready(function() {
show_openid = function() {
$('#openid').show();
$('#standard').hide();
$('#openid_link').hide();
$('#standard_link').show();
createCookie('use_openid', 1, 30);
$('#openid_url').value = 'http://';
}
which will place the script tags with proper attributes around the
code, include CDATA tags.
A description of filters is given at
http://haml.hamptoncatlin.com/docs/rdoc/classes/Haml.html near the
bottom of the page.
>
> <div style="text-align: center; font-size: 12px; padding: 10px;">
> <%= link_to "or Sign up", signup_path %> <br />
> <%- if global_prefs.can_send_email? -%>
> <%= link_to "I forgot my password!",
> new_password_reminder_path %> ::
> <%- end -%>
> [...snip...]
> I am not sure how to deal with style attribute and inline javascript
> code, e.g., onclick="show_openid()..."
You can pass html attributes as a hash:
%div{:style => 'text-align: center;font-size: 12px; padding: 10px;'}
= link_to "or Sign up", signup_path
- if global_prefs.can_send_email?
=link_to "I forgot my password!", new_password_reminder_path
>
> Thanks in advance for your time.
>
> Bharat
>
I hope this helps you further a bit :)
Also, for the forms, I would suggest looking into form_for blocks:
http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
For instance:
<% form_for :person, @person, :url => { :action => "create" } do |f| %>
<%= f.text_field :first_name %>
<%= f.text_field :last_name %>
<%= submit_tag 'Create' %>
<% end %>
could be done as:
- form_for :person, @person, :url => { :action => "create" } do |f|
= f.text_field :first_name
= f.text_field :last_name
= f.submit 'Create'
-Filip H.F. "FiXato" Slagter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---