Skip to content

Instantly share code, notes, and snippets.

View geralch's full-sized avatar
🐱
(。・ω・)ノ゙

Geraldine Caicedo geralch

🐱
(。・ω・)ノ゙
View GitHub Profile
# Install ruby 1.8.6 using the one-click windows installer from:
# http://www.ruby-lang.org/en/downloads/
# Be sure to check the box to enable rubygems during the install.
# Make sure C:\bin exists and is in your path.
# Now open a command-prompt and run:
> gem install pik
> pik_install C:\bin
> pik install ruby 1.8.7
> pik use 187
@jcasimir
jcasimir / render_and_redirect.markdown
Created September 11, 2011 21:29
Render and Redirect in Rails 3

Render and Redirect

The normal controller/view flow is to display a view template corresponding to the current controller action, but sometimes we want to change that. We use render in a controller when we want to respond within the current request, and redirect_to when we want to spawn a new request.

Render

The render method is very overloaded in Rails. Most developers encounter it within the view template, using render :partial => 'form' or render @post.comments, but here we'll focus on usage within the controller.

:action

require 'csv'
CSV.foreach('app/services/rg_list.csv', headers: true) do |row|
Person.find_or_create_by name: row['Name'].to_s.split.map(&:capitalize).join(' '), email: row['Email'].to_s.downcase, gender: row['Gender'].to_s.downcase
end
CSV.foreach('app/services/rg17_register_full.csv', headers: true) do |row|
Person.find_or_create_by name: row['Name'].to_s.split.map(&:capitalize).join(' '), email: row['Email'].to_s.downcase.strip, gender: row['Gender'].to_s.downcase, register_date: row['register_date'].to_s.downcase, birth_date: row['birth_date'].to_s, phone: row['phone'].to_s.downcase.strip, level: row['level'].to_s.downcase, motivation: row['motivation'].to_s.downcase, heard_ror: row['heard_ror'].to_s.downcase, laptop: row['laptop'].to_s.downcase, so: row['so'].to_s.downcase, expectation: row['expectation'].to_s.downcase, how_did_you_find_it: row['how_did_you_find_it'].to_s.downcase
end
CSV.open("file.csv", "wb") do |csv|
csv << ["Name", "Phone"]
people = Person.by_role("assistant").by_gender("f").by_days("vs")
people.each do |p|
p.phone[5..9] = "xxxxx"
csv << [p.name, p.phone]
end
people = Person.by_role("assistant").by_gender("f").by_days("s")
people.each do |p|
csv << [p.name, p.phone]