“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey (contact@robl.me)
Senior Software Engineer, Brighton, UK

Links that are really POSTs

I’m really not a fan of using GETs to call actions that create things like so.

<%= link_to image_tag('mini_icons/copy.png', :alt => 'Make a copy of this lesson'), copy_lesson_path(lesson), :method => :post %>  <br/>
<%= link_to "Copy", copy_lesson_path(lesson), :method => :post %>

Despite using a form to pretend to be a link I much prefer this solution, because it actually enforces a POST to call the ‘copy’ action rather then pretending to be a post with a param { “_method” => “post” }

<% form_for lesson, :url => {:controller => '/lessons', :action => :copy, :id => lesson}, :html => { :method => :post, :class => 'button' } do |f| %>
  <label for="copy">
    <%= image_submit_tag('mini_icons/copy.gif', :alt => 'Copy Lesson', :id => 'copy') %>
    <span>Copy</span>
  </label>
<% end %>