Created
December 16, 2012 17:53
-
-
Save zlw/4310251 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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