Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Juergen Helmers's Profile

GitHub User: helmerj

Site: http://www.web-now.de

Comments by Juergen Helmers

Avatar

Don't use Active Record but create an SQL statement so the data insert is done in a single statement:

ruby
inserts = []

loop around your data do |line|
inserts.push("('#{Time.now}'::timestamp, \
'#{Time.now}'::timestamp,'#{line[0]}','#{line[1]}', \
#{current_user.id})")
end


sql_query = "INSERT INTO table_name (created_at,updated_at,attribute1, attribute2,user_id,) VALUES #{inserts.join(", ")}"

ActiveRecord::Base.connection.execute sql_query

This will take each array element and joins them with a comma to have a long single sql statement which is then executed. Make sure you don't have any single quotes in your incoming data. When using postgres you can replace them with two single quotes '' to allow them to be used as attribute values.

Avatar

I am using will_paginate in a search page. After restricting the number of records according to the search form fields I am calling paginate on them.

When I export to CSV I only export the current number of records on the page as defined in :per_page. How do I trick my controller to export all records when export to CSV?

Avatar

<%= link_to "Excel", user_contacts_path(format: 'xls'), :letter => 'c' %>

should do it...

Avatar

Thanks for the screencast. We have been using refinerycms extensively and really like it a lot. Now that the new version is out it seems time to check it out.

Avatar

Thanks as always Ryan for a great screencast. Are there any know gem incompatibilities with the new rails 3.1? E.g. We use refinerycms a lot and there it seems it is not compatiable out of the box yet.

Cheers Juergen

Avatar

Hi Ryan,

thanks for the great episode. After watching it it was keen trying it myself and downloaded the complete source code. After extraction I installed the bundle, did a "rake db:migrate" and tested the app in the browser, all worked fine.

When following the coding using the auth-before tree as a start I soon got this error:

Failure/Error: let(:user) { Factory(:user) }
     ActiveRecord::StatementInvalid:
       Could not find table 'users'

I checked in the auth-after (bundle, rake db:migrate, guard) and I do get the same error. So there must be something wrong with my testing environment as the regular development environment find the user table in the browser. I am on Ubuntu Linux, I installed/updated libnotify, rb-inotify, and childprocess as guard did complain about not finding them or them being out-dated...

Any help would be appreciated.

Cheers Juergen

SOLVED:

rake db:test:prepare

Should have guessed... sigh

Avatar

Hi Ken,
you could use the above mentioned compass for that. Compass nicely integrates with rails but you can use it without it as well. You will need to run a watch process from the terminal though to monitor changes to your sass/scss files that then get compiled into css-stylesheets on the fly. Find out more about it here:
http://compass-style.org/install

Cheers J.

Avatar

Thanks for the railscasts!

It is great to see SASS being more integrated into rails 3.1. We have been using sass for all our projects for over a year now. The variables and mixins are such a time saver and clean up the resulting CSS code considerably. We prefer to use compass and sass files though as compass gives up great automated mixins and SASS is as nice as HAML is for views. But that is personal preference I guess...

Avatar

Like the new design and I am very much looking forward to rails 3.1 as well as your episodes to let us know what it can do!

Avatar

Very nice screencast! Looks like an elegant way to code an advanced search for a site.