formatting jquery js.erb question
How can I make this on multiple lines. I tried but it does not work.
开发者_JAVA百科$('#wall-top').after("<div id='buttons' style='display: block;'><%=escape_javascript(link_to (image_tag 'btn-post-greeting.png', :width => '241', :height => '68', :alt => 'Btn Post Greeting', :id => 'BtnBoxGreeting'), new_greeting_path, :remote => true) %><%=escape_javascript(link_to (image_tag 'btn-invite-friends.png', :width => '245', :height => '68', :alt => 'Invite Friends', :id => 'BtnBoxFriends'), new_greeting_path, :remote => true, :style => 'display: block;') %></div>");
Pull the ERB chunks out into separate JavaScript variables, format the ERB any way you want, and then paste it all together in JavaScript land. Perhaps something like this:
var greet = '<%=escape_javascript(
link_to(
image_tag('btn-post-greeting.png',
:width => '241',
:height => '68',
:alt => 'Btn Post Greeting',
:id => 'BtnBoxGreeting'
)
),
new_greeting_path,
:remote => true
) %>';
var invite = '<%=escape_javascript(
link_to(
image_tag('btn-invite-friends.png',
:width => '245',
:height => '68',
:alt => 'Invite Friends',
:id => 'BtnBoxFriends'
)
),
new_greeting_path,
:remote => true,
:style => 'display: block;'
) %>';
$('#wall-top').after(
'<div id="buttons" style="display: block;">'
+ greet
+ invite
+ '</div>'
);
That should get you started. I'd go a bit further and move the style
attributes into your style sheet; that would cut down on the noise and give you a cleaner separation of concerns.
精彩评论