Use Rails helpers for the edit button

Instead of creating id and routes manually, use the helpers that Rails
provides in order to do this for us.
This commit is contained in:
Matt Rogers 2015-02-18 08:20:23 -06:00
parent e39177b82d
commit 3bef4daacc
2 changed files with 13 additions and 3 deletions

View file

@ -154,10 +154,10 @@ module TodosHelper
def remote_edit_button(todo=@todo)
link_to(
image_tag("blank.png", :alt => t('todos.edit'), :align => "absmiddle", :id => 'edit_icon_todo_'+todo.id.to_s, :class => 'edit_item'),
{:controller => 'todos', :action => 'edit', :id => todo.id},
image_tag("blank.png", :alt => t('todos.edit'), :align => "absmiddle", :id => dom_id(todo, "edit_icon"), :class => 'edit_item'),
edit_todo_path(todo),
:class => "icon edit_item",
:id => "icon_edit_todo_#{todo.id}",
:id => dom_id(todo, "icon_edit"),
:title => t('todos.edit_action_with_description', :description => todo.description))
end

View file

@ -0,0 +1,10 @@
require "test_helper"
class TodosHelpersTest < ActionView::TestCase
include TodosHelper
test "remote_edit_button" do
html = remote_edit_button(todos(:call_bill))
assert_equal "<a class=\"icon edit_item\" href=\"/todos/1/edit\" id=\"icon_edit_todo_1\" title=\"Edit the action &#39;Call Bill Gates to find out how much he makes per day&#39;\"><img align=\"absmiddle\" alt=\"Edit\" class=\"edit_item\" id=\"edit_icon_todo_1\" src=\"/images/blank.png\" /></a>", html
end
end