Rob Lacey

Brighton, UK - contact@robl.me

Software Engineer working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working at Juniper Education making code for UK schools.


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 %>