Roo getting number instead of text - ruby-on-rails

I am using roo to parse out an excel sheet like this
worksheet.parse(
:partNo => "PM_PartNo",
:salePartNo => "PM_SalesPartNo",
:appSearchInclude => "PM_AppSearchInclude",
:desc => "PM_WebApp_Description",
:brand => "PM_Brand",
:appSegment => "PM_ApplicationSegment",
:group => "PM_ProductGroup",
:design => "PM_ProductDesign",
:material => "PM_Material",
:line => "PM_ProdLine",
:baseSeries => "PM_BaseSeries",
:colorCode => "PM_ColorCode",
:series => "PM_Series",
:weightType => "PM_oz_gram",
:appRim => "PM_ApplicationRim",
:coating => "PM_Coating",
:pcs => "PM_PCSconversion",
:clean => true
) do |hash|
However, Roo keeps giving me a number 200275577.0 for the PM_PartNo column. In the excel sheet, this column has all cells formatted as text. What is should return in the parse is "200275577" as text, not 200275577.0 as a number. Is there a way to ensure it adheres to the excel formatting?

This is an open issue with roo. There is a general workaround contributed by a user in the issue, or you can just convert the value yourself with .to_i.to_s.

Related

Ruby on Rails Roo Import Excel Return NIL

So, I am developing an Ruby on Rails website to import an Excel file into our website. I followed RailsCasts and using Roo gem. All are working, but when the import process done, all fields are nil. When I checked with raise, I found out that the data is nil.
def self.import(file)
spreadsheet = open_spreadsheet(file)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
product = find_by_id(row["id"]) || new
product.attributes = row.to_hash.slice(*accessible_attributes)
product.save!
end
end
When I raised row, I got whole data from Excel. But when I raised product, I got nil. How I can put the data correctly so I can get all value correctly? Thank you.
So, after did some practices, I found out that on first test, it was a hash, so what I need to make it work is actually simple but I am not sure if this is the best practice. If someone have a better practice, it will be a good thing, but this is my solution for now.
object = Lead.new(
:first_name => row['First Name'], :last_name => row['Last Name'],
:address => row['Address'], :city => row['City'],
:state => row['State'], :county => row['County'],
:zip_code => row['Zip Code'], :bedrooms => row['Bedrooms'], :bathrooms => row['Bathrooms'],
:last_sale_date => row['Last Sale Date'], :amount_sold => row['Amount Sold'],
:tax_value => row['Tax Value'], :tax_name => row['Tax Name'], :tax_address => row['Tax Address'],
:tax_city => row['Tax City'], :tax_state => row['Tax State'], :tax_postal_code => row['Tax Postal Code'],
:listing_status => row['Listing Status'], :property_type => row['Property Type'],
:square_footage => row['Square Footage'], :days_on_market => row['Days on Market'], :list_date => row['List Date'],
:status_change_date => row['Status Change Date'], :year_built => row['Year Built'],
:mls_id => row['MLS ID'], :last_call_result => row['Last Call Result'], :last_dial_date => row['Last Dial Date'],
:last_contacted => row['Last Contacted'], :last_dial_time => row['Last Dial Time'], :create_date => row['Create Date'],
:edit_date => row['Edit Date'], :source => row['Source'], :list => row['List'],
:call_attempts => row['Call Attempts'], :family_member => row['Family Member'], :notes => row['Notes'],
:group => row['Group'], :manager => row['Manager']
)

Defacing the Title on Spree Admin pages

I would like to change the title on spree admin pages, and i`m trying to do that on deface:
Deface::Override.new(:virtual_path => 'spree/admin/shared/_header.html.erb',
:name => 'override',
:replace => 'title') do
'<title>MyOnly Administrativo</title>'
end
This is not working at all....
A little bit of work later I figured out what works, that is:
Deface::Override.new(:virtual_path => 'spree/admin/shared/_head',
:name => 'override',
:replace_contents => 'title',
:text => 'MyOnly Administrativo')

Searching with multiple conditions (Ruby on Rails)

I want to search a table with multiple conditions in Rails.
I am working on deleting certain package(record) from database but first i need to get userId and packageID .
and here is the code i wrote but it gives error.
#package=Packages.find(:all, :condition => {:id => params[:pid]}, :condition => {:senders_id => cookies[ :user_id ]})
here is the error :
ArgumentError in CreatePackagesController#deletepackage
Unknown key: condition
i just need equivalent code with the right syntax to that one if someone could help.
def deletepackage
#package=Packages.find(:all, :conditions => {:id => params[:pid], :senders_id => cookies[ :user_id ]}
if (#package!=nil && req.receivedByCarrier==false)
#package.destroy
elsif (#package!=nil && req.receivedByCarrier==true)
#package.destroy
end
return;
end
Change your query as below:
#package = Packages.find(:all, :conditions => {:id => params[:pid], :senders_id => cookies[:user_id]})
You are getting the error as Unknown key: condition because :condition is not a valid option in find method.
:condition should be :conditions (Note plural). Also, you should be passing both the conditions as a single key-value pair.
For Rails 4.x
You can simply do it as below
#package = Packages.where(id: params[:pid], senders_id: cookies[:user_id])
This
#package=Packages.find(:all, :condition => {:id => params[:pid]}, :condition => {:senders_id => cookies[ :user_id ]})
should be like this
#package=Packages.find(:all, :conditions => {:id => params[:pid]}, :senders_id => cookies[ :user_id ]})

Why wash_out can't use identical data types in different soap actions?

I use wash_out from the master branch.
Why I can't use identical data types in different soap actions?
Sample:
soap_action "get_groups",
:args => {:page => :integer},
:return => {:data => [{:id => :integer, :name => :string}], :total => :integer}
soap_action "get_items",
:args => {:page => :integer},
:return => {:data => [{:id => :integer, :name => :string}], :total => :integer}
Also I tried wrap it in WashOut::Type but it not help.
Error:
ActionView::Template::Error (Duplicate use of `data` type name. Consider using classified types.)
I found a solution for myself.
WashOut can't work with nested objects.
Every hash must be replaced with WashOut::Type.
It should look like this:
{:data => [SomeType], :total => :integer}

Search by ID, no keyword. Tried using :conditions but no result ouput

Using Thinking Sphinx, Rails 2.3.8.
I don't have a keyword to search, but I wanna search by shop_id which is indexed. Here's my code:
#country = Country.search '', {
:with => {:shop_id => params[:shop_id]},
:group_by => 'state_id',
:group_function => :attr,
:page => params[:page]
}
The one above works. But I thought the '' is rather redundant. So I replaced it with :conditions resulting as:
#country = Country.search :conditions => {
:with => {:shop_id => params[:shop_id]},
:group_by => 'state_id',
:group_function => :attr,
:page => params[:page]
}
But then it gives 0 result. What is the correct code?
Thanks.
Have a go in the console and see if you cant shift the :conditions around. It looks like by removing the blank string you simply have set a default param for the gem. Get the Gem in your Vendor and have a look at the Country Class to see what is accepts.

Resources