Re: [Rails-core] Problem in saving fields to database from csv using fastercsv

2011-03-23 Thread Surya
Ok, Thanks for letting me know about this.

On Wed, Mar 23, 2011 at 11:15 PM, Matt Jones  wrote:

>
> On Mar 23, 2011, at 9:42 AM, Surya wrote:
>
> > Hi,
> >
> > First of all very sorry for this long post. I am trying to save my csv
> data to table items which is associated with Item model.
> >
> > This is what my csv have:
> > 'name';'number';'sub_category_id';'category_id';'quantity';'sku';
> 'description';'cost_price';'selling_price'
> > 'Uploaded Item Number 1';'54';'KRT';'WN';'67';'WNKRT0054';'Some
> Description here!!';'780';'890'
> > 'Uploaded Item Number 2';'74';'KRT';'WN';'98;'WNKRT0074';'Some
> Description here!!';'8660';'9790'
> >
> > First row show the fields for items table.
> >
> > Here I am using fastercsv to process my csv and paperclip to upload.
> >
> > I am able to process file read content and able to fill up the field too
> here is the processing code:
> >
> > def proc_csv
> > @import = Import.find(params[:id])
> > @lines = parse_csv_file(@import.csv.path)
> > @lines.shift
>
> As others have pointed out, this isn't the right place for this. In any
> case, I suspect your issue is that Excel has spit out a UTF-16 file and you
> didn't tell whatever's parsing it about that...
>
> --Matt Jones
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-core+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
>
>


-- 

Please consider the environment before printing this email.

Regards,
Surya

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.



[Rails-core] Re: 909588d causes breakage if foreign keys are used

2011-03-23 Thread José Valim
Note: it seems google ignored my original post. Sorry if it ends up
twice.

Yes, it is a bug.

Here is a very simple fix that considers your scenario and the one in
the original patch: https://gist.github.com/883459

If you can provide a failing test, we can commit the fix + tests
straight away. :D Thanks for reporting!

On Mar 5, 6:40 pm, Frederick Cheung 
wrote:
> 909588d (forhttps://rails.lighthouseapp.com/projects/8994/tickets/6191) 
> reordered how destroy works with has and belongs to many.
>
> The intent of the change is to ensure that before_destroy is called before 
> any destroying happens which sounds right, but does it by removing the join 
> table records after the owner is destroyed. This breaks all of my foreign key 
> backed habtm associations since the foreign key won't allow deleting the 
> owner while there are still join records pointing at it.
>
> Was this an oversight? Having all the before_destroy callbacks run first 
> definitely feels right, but I'd much prefer that this didn't clash with 
> foreign keys (even if the default rails position isn't to use database 
> constraints)
>
> Fred

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.



Re: [Rails-core] Problem in saving fields to database from csv using fastercsv

2011-03-23 Thread Matt Jones

On Mar 23, 2011, at 9:42 AM, Surya wrote:

> Hi,
> 
> First of all very sorry for this long post. I am trying to save my csv data 
> to table items which is associated with Item model.
> 
> This is what my csv have:
> 'name';'number';'sub_category_id';'category_id';'quantity';'sku'; 
> 'description';'cost_price';'selling_price'
> 'Uploaded Item Number 1';'54';'KRT';'WN';'67';'WNKRT0054';'Some Description 
> here!!';'780';'890'
> 'Uploaded Item Number 2';'74';'KRT';'WN';'98;'WNKRT0074';'Some Description 
> here!!';'8660';'9790'
> 
> First row show the fields for items table.
> 
> Here I am using fastercsv to process my csv and paperclip to upload.
> 
> I am able to process file read content and able to fill up the field too here 
> is the processing code:
> 
> def proc_csv
> @import = Import.find(params[:id])
> @lines = parse_csv_file(@import.csv.path)
> @lines.shift

As others have pointed out, this isn't the right place for this. In any case, I 
suspect your issue is that Excel has spit out a UTF-16 file and you didn't tell 
whatever's parsing it about that...

--Matt Jones


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.



[Rails-core] Re: 909588d causes breakage if foreign keys are used

2011-03-23 Thread José Valim
Yes, it is a bug.

Here is a very simply fix that considers both your scenario and the
one in the original patch: https://gist.github.com/883459

Once we have a test case, I can apply and get this fixed. :D Thanks
for reporting!

On Mar 5, 6:40 pm, Frederick Cheung 
wrote:
> 909588d (forhttps://rails.lighthouseapp.com/projects/8994/tickets/6191) 
> reordered how destroy works with has and belongs to many.
>
> The intent of the change is to ensure that before_destroy is called before 
> any destroying happens which sounds right, but does it by removing the join 
> table records after the owner is destroyed. This breaks all of my foreign key 
> backed habtm associations since the foreign key won't allow deleting the 
> owner while there are still join records pointing at it.
>
> Was this an oversight? Having all the before_destroy callbacks run first 
> definitely feels right, but I'd much prefer that this didn't clash with 
> foreign keys (even if the default rails position isn't to use database 
> constraints)
>
> Fred

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.



Re: [Rails-core] Problem in saving fields to database from csv using fastercsv

2011-03-23 Thread Jason King
This is not the right place for this sort of question, use the
rubyonrails-talk group instead.
On Mar 23, 2011 8:45 AM, "Surya"  wrote:
> Hi,
>
> First of all very sorry for this long post. I am trying to save my csv
data
> to table items which is associated with Item model.
>
> This is what my csv have:
>
> 'name';'number';'sub_category_id';'category_id';'quantity';'sku';
> 'description';'cost_price';'selling_price'
> 'Uploaded Item Number 1';'54';'KRT';'WN';'67';'WNKRT0054';'Some
Description
> here!!';'780';'890'
> 'Uploaded Item Number 2';'74';'KRT';'WN';'98;'WNKRT0074';'Some Description
> here!!';'8660';'9790'
>
>
> First row show the fields for items table.
>
> Here I am using fastercsv to process my csv and paperclip to upload.
>
> I am able to process file read content and able to fill up the field too
> here is the processing code:
>
> def proc_csv
> @import = Import.find(params[:id])
> @lines = parse_csv_file(@import.csv.path)
> @lines.shift
> @lines.each do |line , j|
> unless line.nil?
> line_split = line.split(";")
> unless ((line_split[0].nil?) or (line_split[1].nil?) or
> (line_split[2].nil?) or (line_split[3].nil?) or (line_split[4].nil?) or
> (line_split[5].nil?))
> # I used puts to get to know about what's going on.
> puts "*"*50+"line_split[0]: #{line_split[0]}"+"*"*50
> puts "*"*50+"line_split[1]: #{line_split[1]}"+"*"*50
> puts "*"*50+"line_split[2]: #{line_split[2]}"+"*"*50
> puts "*"*50+"line_split[3]: #{line_split[3]}"+"*"*50
> puts "*"*50+"line_split[4]: #{line_split[4]}"+"*"*50
> puts "*"*50+"line_split[5]: #{line_split[5]}"+"*"*50
> puts "*"*50+"line_split[6]: #{line_split[6]}"+"*"*50
> puts "*"*50+"line_split[7]: #{line_split[7]}"+"*"*50
> puts "*"*50+"line_split[8]: #{line_split[8]}"+"*"*50
>
> @item = [:name => line_split[0], :number => line_split[1],
> :sub_category_id => line_split[2],:category_id => line_split[3],:quantity
=>
> line_split[4], :sku => line_split[5], :description => line_split[6],
> :cost_price => line_split[7], :selling_price => line_split[8]]
> puts "#"*100+"@item is: #{@item.inspect}"+"#"*100
>
> end
> end
> end
> redirect_to import_path(@import)
> end
>
>
> but the problem is that when it process it and when I check the @item in
> console it looks like this:
>
>
@item
> is: [{:quantity=>"\000'\0006\0007\000'\000",
> :name=>"\000'\000U\000p\000l\000o\000a\000d\000e\000d\000
> \000I\000t\000e\000m\000 \000N\000u\000m\000b\000e\000r\000
\0001\000'\000",
> :sku=>"\000'\000W\000N\000K\000R\000T\\\0005\0004\000'\000",
> :cost_price=>"\000'\0007\0008\\000'\000",
> :number=>"\000'\0005\0004\000'\000",
> :selling_price=>"\000'\0008\0009\\000'\000",
> :sub_category_id=>"\000'\000K\000R\000T\000'\000",
> :description=>"\000'\000S\000o\000m\000e\000
> \000D\000e\000s\000c\000r\000i\000p\000t\000i\000o\000n\000
> \000h\000e\000r\000e\000!\000!\000'\000",
>
:category_id=>"\000'\000W\000N\000'\000"}]
>
>
@item
> is: [{:quantity=>"\000'\0009\0008\000",
> :name=>"\000'\000U\000p\000l\000o\000a\000d\000e\000d\000
> \000I\000t\000e\000m\000 \000N\000u\000m\000b\000e\000r\000
\0002\000'\000",
> :sku=>"\000'\000W\000N\000K\000R\000T\\\0007\0004\000'\000",
> :cost_price=>"\000'\0008\0006\0006\\000'\000",
> :number=>"\000'\0007\0004\000'\000",
> :selling_price=>"\000'\0009\0007\0009\\000'\000",
> :sub_category_id=>"\000'\000K\000R\000T\000'\000",
> :description=>"\000'\000S\000o\000m\000e\000
> \000D\000e\000s\000c\000r\000i\000p\000t\000i\000o\000n\000
> \000h\000e\000r\000e\000!\000!\000'\000",
>
:category_id=>"\000'\000W\000N\000'\000"}]
>
>
> Can anyone kindly tell me why am I getting this kind of string instead of
> simple string I entered in my csv file? And because of this it's not being
> saved into the table too, I have tried all possible formats but nothing
> seems to be working. I want "Uploaded Item Number 1" instead of
> "\000'\0006\0007\000'\000",
> :name=>"\000'\000U\000p\000l\000o\000a\000d\000e\000d\000
> \000I\000t\000e\000m\000 \000N\000u\000m\000b\000e\000r\000
> \0001\000'\000" . Any help will be appreciated. Thanks in advance :)
>
> --
>
> Please consider the environment before printing this email.
>
> Regards,
> Surya
>
> --
> You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> To unsubscribe from this group, send email to
rubyonrails-core+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.
>

-- 
You received this message because you a

[Rails-core] Passing NilClass To Create & MiniTest Backtrace Cleaner

2011-03-23 Thread Ken Collins

Morning All!

Some things I noticed while playing with 3.1 master last night.

1) When using the #create! method on an association and pass "nil" vs an empty 
hash, now fails silently with no warning or anything. It's almost like a no-op. 
I did not test to see if this behavior occurred on a basic model or not. My 
app's controller was setup in such a way that I would always pass params[:foo] 
and sometimes that was nil and for years that has always worked. Does this 
sound patch worthy? If so I'll scrap some time up and see what happens.

2) I noticed that the Rails.backtrace_cleaner was not being used in my tests 
under 1.9.x since that uses MiniTest. This could have been happening for as 
long as there has been MiniTest usage since the backtrace cleaner was 
introduced, I may have never noticed before. Either way I created a plugin last 
night [1] called MiniBacktrace that is really just a few lines of code [2]. I'd 
be willing to submit a patch if you think this is helpful. I could easily check 
to see if the version of MiniTest supports the method chain interface to make 
this happen or take other advice. I found it really helpful :)

[1] https://github.com/metaskills/mini_backtrace
[2] 
https://github.com/metaskills/mini_backtrace/blob/master/lib/mini_backtrace/unit.rb


 - Thanks,
Ken


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.