javascript - Can't get flash or error messages to display on button submit -
i have form , i'm trying submit contents of form model "leeds" display success/failure message depending on if data passes model validations.
the issue i'm having when click on "send message" button, takes me root
root/leeds
.
this form i'm using:
<%= form_for @leed, {url:root_path, html: {id:"contactform", name:"sentmessage", novalidate:true}} |leed| %> <div class="row"> <div class="col-md-6"> <!-- name --> <div class="form-group"> <%= leed.text_field :name, class: "form-control", :placeholder => "your name *", :required => true, :data => {:validation_required_message => 'please enter name.' } %> <p class="help-block text-danger"></p> </div> <!-- email --> <div class="form-group"> <%= leed.email_field :email, class: "form-control", :placeholder => "your email *", :required => true, :data => {:validation_required_message => 'please enter email address.' } %> <p class="help-block text-danger"></p> </div> <!-- phone --> <div class="form-group"> <%= leed.telephone_field :phone, class: "form-control", :placeholder => "your phone *", :required => true, :data => {:validation_required_message => 'please enter phone number.' } %> <p class="help-block text-danger"></p> </div> </div> <!-- message --> <div class="col-md-6"> <div class="form-group"> <%= leed.text_area :message, class: "form-control", :placeholder => "your message *", :required => true, :data => {:validation_required_message => 'please enter message.' } %> <p class="help-block text-danger"></p> </div> </div> <div class="clearfix"></div> <!-- submit --> <div class="col-lg-12 text-center"> <div id="success"> <%= render 'shared/error_messages' %> </div> <%= button_tag "send message", class: "btn btn-xl" %> </div> </div> <% end %>
this routes.rb:
rails.application.routes.draw root 'home#index' post "/" => 'home#create' end
this homecontroller method have:
def create @leed = leed.new(leed_params) if @leed.save #update page reflect success flash[:success] = "thank you, we'll contact possible" else #update page flect failure flash[:danger] = "there issue login attempt #{@leed.errors.full_messages.inspect}" end # redirect_to thank_you.html.erb render nothing:true end
at end of #create method have render nothing: true
. means post request submitted /leads, server won't tell browser go anywhere else, browser stay @ /leads url. can add redirect @ end of create action if want browser redirected different page after post request completed. hope helps!
Comments
Post a Comment