Forum: Ruby on Rails link_to_remote

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Justin M. (Guest)
on 2009-05-11 08:34
I'm trying to execute a javscript block using link_to_remote

here's my code:


  <%= link_to_function("Add a follow-up date for this note?", nil, :id
=> "show_link") do |page| %>
    <% page[:follow_up_date_select].visual_effect :toggle_appear %>
    <% page[:show_link].replace_html "Hide date select" %>
  <% end %>

It's throwing some errors that I can't figure out:

syntax error, unexpected ')'
@output_buffer.concat "  "; @output_buffer.concat((
link_to_function("Add a follow-up date for this note?", nil, :id =>
"show_link") do |page| ).to_s); @output_buffer.concat "\n"
Siddick E. (Guest)
on 2009-05-11 09:19
Solution :-
    <%= link_to_function("Add a follow-up date for this note?", nil, :id
=> "show_link") do |page|
              page[:follow_up_date_select].visual_effect :toggle_appear
              page[:show_link].replace_html "Hide date select"
     end %>
Justin M. (Guest)
on 2009-05-11 23:41
Siddick E. wrote:
> Solution :-
>     <%= link_to_function("Add a follow-up date for this note?", nil, :id
> => "show_link") do |page|
>               page[:follow_up_date_select].visual_effect :toggle_appear
>               page[:show_link].replace_html "Hide date select"
>      end %>

That worked.

I've set up link_to_function with a block that inserts a chunk of html
from a partial when the link is clicked -- namely a data select. I'm
wondering if I can use the same block to replace the link that's
executing the function?

For example, after a user clicks on "Add a follow-up-date" and the date
select appears, is there an easy way for me to replace the link with a
"nevermind" or something that can then removed the date select? Or
should I have the partial render a button that takes it away, instead of
trying to update the add link? Here's the exact code I'm using now.

 <%= link_to_function("Add a follow-up date?", nil, :id =>
"add_follow_up_link") do |page|
      page.insert_html :after, 'add_follow_up_link', :partial =>
'follow_up'
      page.visual_effect :toggle_appear, "follow_up_date_select"
    end %>


And here's the partial:

<span id="follow_up_date_select" style="display:none">
  <%= date_select (:action_date, :order => [:month, :day, :year]) %>
</span>

My instinct is to just add a button in the partial that will call
another javascript function to take this away. But the other problem
with leaving the add link functioning on the page after it's been
clicked is that if a user accidentally clicks on it again, the partial
is rendered again and I have two identical date_selects on the page.
This topic is locked and can not be replied to.