ruby on rails - Coffeescript alert doesn't displays -
i might have error on coffeescript. have contact form , when submit don't have notice if succeed or fail.
$(document).ready -> $("#new_contact").on("ajax:success", (e, data, status, xhr) -> $("#new_contact").append xhr.responsetext alert ":) received it" $(this.el).css("background-color", "#333") $('.contact_form').css({'background-color':'#88ff88'}).animate({'background-color':'#114411'}, 1000) ).bind "ajax:error", (e, xhr, status, error) -> $("#new_contact").append "<p>error</p>" alert "something went wrong :( try again or contact me email."
the contact form on onepage app
def create @contact = contact.new(params[:contact]) @contact.request = request respond_to |format| if @contact.deliver flash.now[:error] = nil format.html {redirect_to(root_path, :notice => "message")} #format.js #flash.now[:notice] = 'thank message!' # else #do escape_javascript @message #@message = 'cannot send message. try again.' flash.now[:error] = 'cannot send message.' format.html {render :index} #format.js end end#respond_to end
and form looks
#<form accept-charset="utf-8" action="http:/app.herokuapp.com/" class="simple_form new_contact" data-remote="true" id="new_contact" method="post"> <%= simple_form_for @contact , :url => root_url, :remote => true |f| %>
for starters, code structure malformed (you don't have any indents)
i got js2coffee:
$(document).ready -> $(document).on("ajax:success", "#new_contact", (e, data, status, xhr) -> $("#new_contact").append xhr.responsetext alert ":) received it" $(@el).css "background-color", "#333" $(".contact_form").css("background-color": "#88ff88").animate "background-color": "#114411" , 1000 return ).on "ajax:error", (e, xhr, status, error) -> $("#new_contact").append "<p>error</p>" alert "something went wrong :( try again or contact me email." return return
Comments
Post a Comment