Skip to content

Instantly share code, notes, and snippets.

@zlw
Created December 16, 2012 17:53
Show Gist options
  • Save zlw/4310251 to your computer and use it in GitHub Desktop.
Save zlw/4310251 to your computer and use it in GitHub Desktop.
def create
begin
n = Mikolaj.create_from_text(params[:s])
respond_to |format|
format.html { redirect_to mikolajs_path, notice: "Dodano #{n} mikolajow" }
format.json { render json: mikolajs_path, status: :created, location: mikolajs_path }
end
rescue ActiveRecord::RecordInvalid
render :new
end
end
class Mikolaj < AR::Base
def self.create_from_text(txt)
txt = txt.split("\n").compact
txt.each do |mikolaj|
create!(name: mikolaj)
end
txt.length
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment