I'm trying to development a little project in Rails with rake-tasks.
First of all, I get some data from the rake-call and I want to store it in the database. The problem: when I try to store the generated data, I always receive an error (unknown attribute: actuals_cost). But when I try to give it manual in, it works...
Here is some of my code:
desc "Import Projects from CRM"
task :import_projects_crm => [:environment] do
crm_projects = Crm::Importer.new().import_projects
Project.create(
:order_number => crm_projects[0][0],
:client_name => crm_projects[0][2],
:partner_name => crm_projects[0][1],
:totals_sales_orders => crm_projects[0][3],
:actuals_cost => crm_projects[0][4],
:actuals_sales => crm_projects[0][5],
:external_cost => crm_projects[0][7],
:external_sales => crm_projects[0][8],
:total_change_request => crm_projects[0][6],
:storage_path_sales_order => crm_projects[0][9],
:storage_path_pm => crm_projects[0][10]
)
#Project.create(:actuals_cost => 100) --> works :(
end
The data is pulled from a SQLServer, thats why I work with the square brackets.
EDIT:
Alright, found the problem. Like I told before. In rake I make a connection with a remote database (SQLServer) and I want to store the data on a local database (PostgreSQL).
The problem was with the connection. When I pulled the data from the SQLServer, you need to switch from database and this is how you can do it.
ActiveRecord::Base.establish_connection :[one_of_databasename_in_your_yaml]