Papouche Guinslyzinho
Papouche Guinslyzinho

Reputation: 5458

Coffeescript alert doesn't displays

I might have some error on my coffeescript. I have a contact form and when I submit it I don't have any notice if it succeed or fail.

$(document).ready ->
$("#new_contact").on("ajax:success", (e, data, status, xhr) ->
$("#new_contact").append xhr.responseText
alert ":) I 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 by email."

The contact form is on a onepage app

  def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    respond_to do |format|
      if @contact.deliver
        flash.now[:error] = nil
        format.html {redirect_to(root_path, :notice => "Message")}
        #format.js
        #flash.now[:notice] = 'Thank you for your 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 my form looks like this

#<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 do |f| %>

Upvotes: 0

Views: 629

Answers (1)

Richard Peck
Richard Peck

Reputation: 76784

For starters, your code structure is malformed (you don't have any indents)

I just got this from JS2Coffee:

$(document).ready ->
  $(document).on("ajax:success", "#new_contact", (e, data, status, xhr) ->
    $("#new_contact").append xhr.responseText
    alert ":) I 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 by email."
    return

  return

Upvotes: 2

Related Questions