Skip to content

Instantly share code, notes, and snippets.

@cored
Created March 22, 2009 19:51
Show Gist options
  • Save cored/83274 to your computer and use it in GitHub Desktop.
Save cored/83274 to your computer and use it in GitHub Desktop.
GlobalHelpers
# helpers defined here available to all views.
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',
:rel => question.id)
end
else
link_to 'interested?', url(:login)
end
end
end
end
class Users < Application
def index
render
end
def show(id)
@user = User.get(id)
raise NotFound unless @user
display @user
end
def interested(id)
provides :js, :html
@question = Question.get(id)
raise NotFound unless @question
interest = Interest.new
interest.question = @question
interest.user = session.user
interest.save
display @question
end
end
jQuery.ajaxSetup({
'beforeSend': function(xhr) { xhr.setRequestHeader("Accept", "text/javascript") }
})
$(document).ready(function() {
$(".remote").click(function(e) {
e.preventDefault();
alert("Hello");
$("#indicator").show();
$("#indicator").hide("slow");
return false;
};)
};)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment