• Stars
    star
    165
  • Rank 220,878 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 12 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

simple_form custom inputs to get image/link previews with file uploads.

SimpleForm fancy uploads

A set of simple_form (~> 4.1) custom inputs to get image previews or a link to uploaded file.

This gem uses the simple_form ability to write your own form tags (check the simple_form-bootstrap example). In 90% of cases, you need some kind of preview when it comes to uploaded files (avatar, images, docs, etc..), why should I write the same markup each time?

What you get

There're only two new file inputs:

  • ImagePreview: guess what? when you edit an entry that contains an uploaded image, it will be shown (how many times did you this in a CMS?)
  • AttachmentPreview: this is a generic upload field, it will show a direct link to the file, so you can check what was uploaded.

How it works

Install

Simply add gem 'simple_form_fancy_uploads' to your Gemfile and run bundle install

Usage

Here's a basic example, as you can see, it's just a matter of specify the input as :image_preview or :attachment_preview. If using :image_preview, you can also specify a :preview_version => :some_version_name inside the :input_html Hash. This will let you to show a custom version generated with Carrierwave. Nice, isn't it?

If you need to fallback on Carrierwave's #default_url method to show a default image defined in your upload class, set :use_default_url => true in the options hash.

<%= simple_form_for @some_model do |f| %>
  <!-- we specify that this is an image form upload input, and we want to show the 'thumb' version
  of the carrierwave upload to not break our layout with a non-resized image -->
  <%= f.input :some_image_field, as: :image_preview, input_html: {preview_version: :thumb} %>

  <!-- here's a *normal* attachment. with this input, a link to the filename will be shown
  if there's an uploaded file -->
  <%= f.input :some_attachment_field, as: :attachment_preview %>
<% end %>

If you want, you can pass the preview_url to the image on the input_html options. This might be useful when you don't have a model binded to the form.

<%= simple_form_for :user do |f| %>
  <%= f.input :image, as: :image_preview, input_html: { preview_url: image_url } %>
<% end %>

Dependencies

To get it work, you need:

  • simple_form ~> 4.1 (repetita iuvant)
  • carrierwave actually it's the most opinionated gem for uploads (thank you paperclip for the good times, but you know... life goes on)
  • ruby 2.2.2+

Testing

  • clone this repo
  • run bundle install
  • run rspec spec

Contributions & Bugs

  • the easy way: go to issues page and blame me.
  • the hard way: repeat the above points, then show your power and send a pull request.

License

Copyright (c) 2014 Andrea Pavoni http://andreapavoni.com

More Repositories

1

panoramic

store rails views on database instead of filesystem
Ruby
169
star
2

nova

An attempt to port/rebuild Spree, an open source e-commerce solution, with Elixir and Phoenix.
Elixir
127
star
3

disco

Simple, opinionated yet flexible library to build CQRS/ES driven systems 🕺
Elixir
34
star
4

picciotto

minimalistic website framework based on Padrino
JavaScript
27
star
5

plug_ets_cache

A simple caching system based on Plug and ETS.
Elixir
25
star
6

flux-tweets

Realtime twitter stream built with NodeJS, React and Flux
JavaScript
17
star
7

12dos-bookmarks

A basic bookmark app
Ruby
17
star
8

rubyday

rubyday.it website
Ruby
9
star
9

mini_cqrs_es

Simple, minimal, opinionated building blocks to implement CQRS/ES in Rust
Rust
9
star
10

operation-go

JavaScript
8
star
11

dotfiles

~/.dotfiles
Lua
7
star
12

nodino

A simple URL shortener built with ExpressJS, React JS and Redis
JavaScript
6
star
13

avarus

a minimalistic URL shortener built with code parsimony in mind
Ruby
4
star
14

likes_tracker

track likes between rails models using Redis backend
Ruby
4
star
15

r12-guessthefriend

"Guess The Friend" game with your Facebook friends
Ruby
4
star
16

vim_starter_kit

a vim configuration with useful bundles
Vim Script
3
star
17

goshort

a simple URL shortener built with Go
CSS
3
star
18

ttfm_bot

A bot to bring some fun and utils on turntable.fm rooms
Go
3
star
19

flat

a semi static cms engine that runs as elixir phoenix web application
Elixir
3
star
20

parabellum

An attempt to build a #Travian 3.x clone written in #Rust.
Rust
3
star
21

gallerizer-jquery-plugin

A jQuery plugin that generates a simple crossfade slideshow
JavaScript
2
star
22

rbcue2txt

Parses cue files from Rekordbox's recordings to produce readable, markdown-friendly playlists.
Rust
2
star
23

robo_radio_rs

A Rust implementation of https://radio.pavonz.com
Rust
2
star
24

cash_cli

Basic CLI app to track personal financing written in #Rust
Rust
1
star
25

txtatus-cli

A very basic http://txtatus.com client to push statuses from command line
Go
1
star
26

stupeflix-client

A Ruby client for http://stupeflix.com API
Ruby
1
star
27

easy_config

Store Ruby or Rails app settings in the easiest way
Ruby
1
star
28

simple_counter

Simple counter experiment made with Rust, Axum, SeaORM, Askama templates and HTMx
Rust
1
star
29

scrobblify

Self-hosted music scrobble database to create personal listening statistics and charts from your Spotify (premium) account.
Rust
1
star