Help with wierd bug

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

Financeiro

<%= label :financial, 'Data' %> <%= date_select(:financial, :date, { :discard_day => true }, { :class => 'financial_date' }) %>

<%= render :partial => 'financial_data', :locals => { :year => @year, :month => @month, :payment_history => @payment_history } %>

_financial_data.html.erb

Year: <%= year %> ---- Month: <%= month %>

Preo pelos clicks: <%=%>

Total a pagar:

<%#= 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

Aren’t you running any tests? You can also test your code in a ruby
program (although rails sometimes adds capabilities that aren’t present
in ruby):

@year = 6

datetime = Time.now
datetime.year = @year

–output:–

ruby.rb:4:in <main>': undefined methodyear=’ for 2011-07-26 17:22:19
-0700:Time (NoMethodError)

And if I insert that code in any of my actions in a rails app, lots of
my tests fail with this error:

  1. UsersController GET show should have a profile image
    Failure/Error: get :show, :id => @user
    NoMethodError:
    undefined method `year=’ for 2011-07-26 17:31:59 -0700:Time

    ./app/controllers/users_controller.rb:6:in `show’

    ./spec/controllers/users_controller_spec.rb:33:in `block (3

levels) in <top (required)>’