Skip to content

Instantly share code, notes, and snippets.

@shlomizadok
Created February 6, 2013 09:32
Show Gist options
  • Save shlomizadok/4721408 to your computer and use it in GitHub Desktop.
Save shlomizadok/4721408 to your computer and use it in GitHub Desktop.
Demonstrates how one can set own cypher for encrypting file with carrierwave_securefile
<%= form_for @book, :html => {:multipart => true} do |f| %>
<% if @book.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@book.errors.count, "error") %> prohibited this book from being saved:</h2>
<ul>
<% @book.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :cypher, t(:encrypt_your_file_with_the_following_cypher) %><br />
<%= f.text_field :cypher %>
</div>
<div class="field">
<%= f.label :file %><br />
<%= f.file_field :file %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
class Book < ActiveRecord::Base
attr_accessible :expiration, :cypher, :file, :user_id, :asset_id
mount_uploader :file, BookUploader
validates :file, :presence => true
def url
file
end
end
class BooksController < ApplicationController
.
.
.
# GET /books/new
# GET /books/new.json
def new
@book = Book.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @book }
end
end
.
.
.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment