Converted the Membership rate form to an Ajax remote form.
* Changed the form_for to be a remote_form_for * Changed the url to use the js format * Added RJS to add the Saved rate to the rate cell * Added id to the table cell so the rate cell can be replaced on success * Added an Error RJS to flash an error message #1921
This commit is contained in:
1 parent
7930144e8c
commit
363e8c0c5a
4 files changed
+18
-4
No files matched your search
@@ -57,12 +57,19 @@ class RatesController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @rate.save
|
if @rate.save
|
||||||
flash[:notice] = 'Rate was successfully created.'
|
format.html {
|
||||||
format.html { redirect_back_or_default(rates_url(:user_id => @rate.user_id)) }
|
flash[:notice] = 'Rate was successfully created.'
|
||||||
|
redirect_back_or_default(rates_url(:user_id => @rate.user_id))
|
||||||
|
}
|
||||||
format.xml { render :xml => @rate, :status => :created, :location => @rate }
|
format.xml { render :xml => @rate, :status => :created, :location => @rate }
|
||||||
|
format.js { render :action => 'create.js.rjs'}
|
||||||
else
|
else
|
||||||
format.html { render :action => "new" }
|
format.html { render :action => "new" }
|
||||||
format.xml { render :xml => @rate.errors, :status => :unprocessable_entity }
|
format.xml { render :xml => @rate.errors, :status => :unprocessable_entity }
|
||||||
|
format.js {
|
||||||
|
flash.now[:error] = 'Error creating a new Rate.'
|
||||||
|
render :action => 'create_error.js.rjs'
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
element = 'rate_' + @rate.project_id.to_s
|
||||||
|
page.replace_html element, "<strong>#{link_to number_to_currency(@rate.amount), { :action => 'edit', :id => @rate.user, :tab => 'rates'} }</strong>"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
content = render_flash_messages
|
||||||
|
page.select("div.flash").each do |value, index|
|
||||||
|
page.hide value
|
||||||
|
end
|
||||||
|
page.insert_html :top, 'content', content
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<%= link_to l(:button_delete), {:action => 'destroy_membership', :id => @user, :membership_id => membership }, :method => :post, :class => 'icon icon-del' %>
|
<%= link_to l(:button_delete), {:action => 'destroy_membership', :id => @user, :membership_id => membership }, :method => :post, :class => 'icon icon-del' %>
|
||||||
</td>
|
</td>
|
||||||
<%# TODO: Hook %>
|
<%# TODO: Hook %>
|
||||||
<td>
|
<td id="rate_<%= membership.project.id %>">
|
||||||
<% rate = Rate.for(@user, membership.project) %>
|
<% rate = Rate.for(@user, membership.project) %>
|
||||||
|
|
||||||
<% if rate.default? || rate.nil? %>
|
<% if rate.default? || rate.nil? %>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
<em><%= number_to_currency(rate.amount) %></em>
|
<em><%= number_to_currency(rate.amount) %></em>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% form_for(:rate, :url => rates_path) do |f| %>
|
<% remote_form_for(:rate, :url => formatted_rates_path('js')) do |f| %>
|
||||||
|
|
||||||
<%= f.text_field :amount %>
|
<%= f.text_field :amount %>
|
||||||
<%= f.hidden_field :date_in_effect, :value => Date.today.to_s %>
|
<%= f.hidden_field :date_in_effect, :value => Date.today.to_s %>
|
||||||
|
|||||||
Reference in new issue
Block a user