I'm doing an ajax call to update a page, and for some reason when I add the
commented lines (any of them, all of them, doesn't matter) my ajax call just
doesn't work (meaning the year and month that are showing wont change).
Below is each code so that you can understand what I'm talking about.
company_pages_controller.rb
def financial
@company = current_company
@year = Time.now.year
@month = Time.now.month
time_range = (Time.now - 1.month)..(Time.now)
@payment_history = PaymentHistory.where(:company_id =>
@company.id).where(:created_at
=> time_range).first
end
def update_financial_data
@company = current_company
@year = params[:year]
@month = params[:month]
datetime = DateTime.now
# datetime.year = @year # essa linha da problema na chamada ajax
# datetime.month = @month
# datetime.day = 1
# datetime = datetime.at_midnight
# time_range = (datetime - 1.day)..(datetime + 1.day)
# @payment_history = PaymentHistory.where(:company_id =>
@company.id).where(:created_at
=> time_range).first
render :partial => 'financial_data', :locals => { :year => @year, :month
=> @month }
end
financial.html.erb
<h1>Financeiro</h1>
<p>
<%= label :financial, 'Data' %>
<%= date_select(:financial, :date, { :discard_day => true }, { :class =>
'financial_date' }) %>
</p>
<div id='financial_data'>
<%= render :partial => 'financial_data', :locals => { :year => @year,
:month => @month,
:payment_history =>
@payment_history } %>
</div>
_financial_data.html.erb
<p>Year: <%= year %> ---- Month: <%= month %></p>
<p>Preço pelos clicks: <%=%></p>
<p>Total a pagar:</p>
<%#= payment_history.created_at unless payment_history.nil? %>
application.js
// Dynamically change financial data for company_pages#financial when
financial date changes
$(function($) {
$('select.financial_date').change(function() {
var year = $('select#financial_date_1i :selected').val();
if(year == '') year = '0';
var month = $('select#financial_date_2i :selected').val();
if(month == '') month = '0';
$.get('/company_pages/update_financial_data/' + year + '/' + month,
function(data){
$("#financial_data").html(data);
})
return false;
});
})
routes.rb
match '/company_pages/financial', :to => 'company_pages#financial'
match '/company_pages/update_financial_data/:year/:month', :to =>
'company_pages#update_financial_data'
Well, I think that's all the relevant stuff. I don't know why (again), but
well I take out the '#' from company_pages_controller or from
_financial_data.html.erb, the ajax call doesn't work anymore.
Thank you,
Rodrigo
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.