On Fri, 20 Mar 2009 08:05:35 -0400
Rafael George <[email protected]> wrote:
>
> Hi guys,
>
> I have a problem regarding doing some javascript effects with
> Merb/jQuery. I'm porting an application from PHP.
>
> I will show so code because i think it's better:
>
>
> module Merb
> module QuestionsHelper
> def link_to_interested_user(question)
> if session.user
> interested = Interest.get(session.user.id, question.id)
> if !interested.nil?
> return 'interested!'
> else
> return link_to 'interested?', url(:user_interested, :id =>
> question.id), :class => 'remote'
> end
> else
> link_to 'interested?', url(:login)
> end
> end
> end
> end # Merb
>
> .interested_mark{ :id => "mark_#{question.id}" }
> = question.interested_users
>
> = link_to_interested_user(question)
>
> Ok, i want to do two things, first i want to show the 'indicator'
> progress gif with jQuery.
>
> $("#remote a").click(function() {
> $("#indicator").show();
> });
>
> The second i want to do, is that when somebody hit the link for the
> 'interested?' it's make a ajax call to the action listed in the helper
> method, so it can increase it's interested
> for that user, this is the code for the action
>
> def interested(id)
> @question = Question.get(id)
> raise NotFound unless @question
>
> interest = Interest.new
> interest.question = @question
> interest.user = session.user
> interest.save
> render @question, :layout => false
> end
>
> And view for the action
>
> = partial '/questions/intereted_user', @question
>
> I'm reusing the same part above, or at least trying because the page
> get's blank when i hit the 'interested?' link.
>
> I set the render layout to false, because i just want to update the
> block where the number resides, the problem is that as you can notice
> the id for the block i want to update with the ajax call it's dynamic
> "mark_#{question.id}", so how can i know which is in the jQuery call.
>
> Thanks in advance.
>
>
>
> --
> Rafael George
>
You know (or can determine) the id of the question via looking at the link the
jQuery is anchored to.
$("#remote a").click(function() {
$("#indicator").show();
$(this).attr("href");
false;
});
In the code above, $(this) is the link in question, and so .attr("href") is the
URL it points to. From there, you should be able to determine the question.id
and so update the appropriate counter.
The 'false' at the end indicates that normal handling of the event (i.e.
following the link you clicked on to the new page) should be stopped.
Regards,
Jon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" 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/merb?hl=en
-~----------~----~----~----~------~----~------~--~---