I'm a bit new to rails and I'm just trying to display a confirmation message when a "Proposition" (created model) has been inserted. For this, I'm using a javascript functionality embedded to rails. Unfortunately, when I click and submission button, the proposition is correctly inserted but I can't find a way to display this confirmation message (like "proposition correctly submitted" for example)...
Below the code that I'm using :
Proposition Model :
class Proposition < ActiveRecord::Base
belongs_to :ad
attr_accessible :email, :name, :phone, :price
validates_presence_of :name or :price or :email or :phone
end
Create method in controller :
def create
@ad = Ad.find(params[:ad_id])
@proposition = @ad.propositions.create(params[:proposition])
respond_to do |format|
if @proposition.save
format.html { redirect_to ad_path(@ad), notice: 'Proposition was successfully created.' }
format.json { render json: ad_path(@ad), status: :created, location: @proposition }
format.js
else
format.html { render action: "new" }
format.json { render json: @proposition.errors, status: :unprocessable_entity }
format.js { render action: "new" }
end
end
end
_form.html.erb :
<%= form_for [@ad, @ad.propositions.build], :remote => true do |f| %>
<% if @proposition.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@proposition.errors.count, "error") %> prohibited this proposition from being saved:</h2>
<ul>
<% @proposition.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :Prénom %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :"Adresse mail" %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :Téléphone %><br />
<%= f.text_field :phone %>
</div>
<div class="field">
<%= f.label :"Prix proposé" %><br />
<%= f.text_field :price %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
create.js.erb :
$('#new_proposition').fadeOut(1000);
new.js.erb :
$('#new_proposition_link').hide().after('<%= j render("form") %>');
Thanks for your help !