Skip to content

Instantly share code, notes, and snippets.

@plexus
Created May 25, 2013 14:51
Show Gist options
  • Save plexus/5649339 to your computer and use it in GitHub Desktop.
Save plexus/5649339 to your computer and use it in GitHub Desktop.

add this to the Gemfile

gem 'auto_html`

Then create a field in the database to store the media URL

rails generate migration add_media_url_to_profiles media_url:string
rake db:migrate

Now add the auto_html functionality to the model

class Profile < ActiveRecord::Base
  include AutoHtml

  auto_html_for :media_url do
    # Here you need to consult
    # https://github.com/dejan/auto_html
    # https://github.com/dejan/auto_html/tree/master/lib/auto_html/filters
    # the important ones are
    html_escape
    youtube
  end
end

Now update you views

# profile/_form.html.erb
<%= form_for @profile do |f| %>
  <%= f.text_field :media_url %> <!-- not 100% sure about the syntax here -->
<%= end %>
```

````ruby
# profile/_show.html.erb
<%= @profile.media_url_html %>
```

Voila!
@thatbettina
Copy link

Hi Arne,

Thanks for your help!

Why do you update # profile/_form.html.erb instead of _profile.html.erb ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment