styles.css
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap");
body {
font-family: 'Roboto', sans-serif;
color: #333;
}
.wrapper {
max-width: 960px;
margin: 0 auto;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
}
about_conttroller.rb
class AboutController < ApplicationController
def index
@info = Info.new
end
def create
@info = Info.new(info_params)
respond_to do |format|
if @info.save
InfoMailer.with(info: @info).notification.deliver_now
format.html {redirect_to about_path}
format.js { alert('Info saved successfully!') }
else
format.html {render :index}
format.json {render json: @info.errors, status: :unprocessable_entity}
end
end
end
private ##
def info_params
params.require(:info).permit(:title, :content)
end
end
trying to test the alert message after saving info in the database.
alert.js.erb
alert('Alert message displayed!');
home.html.haml
.main_info_inner
= form_for @info , url: info_path do |f|
- if @info.errors.any?
%ul
- @info.errors.full_messages.each do |msg|
%li= msg
#infoForm.row.info_form
.form-group.col-md-6
= f.text_field :title, class: 'form-control', placeholder: 'Title'
.form-group.col-md-6
= f.text_area :content, class: 'form-control', placeholder: 'Content'
.form-group.col-md-12
%button.btn.submit_btn.blue.form-control{:type => "submit", :value => "submit"} Save
No console log is shown after submitting the form.
If you have any ideas on how to troubleshoot format.js not executing properly or alternative ways to create alerts without using controllers, your assistance would be greatly appreciated.