Rails - Undefined method `stringify_keys'

Ruby on-Rails

Ruby on-Rails Problem Overview


I'm trying to create a block of ruby code for when a user clicks on the back button. I'm getting the error "undefined method `stringify_keys' for "/projects/11/steps/4":String". The code works when I get rid of the do and end. How do I add a do to a link_to?

    <%= link_to 'Back', project_step_path(@project, @project.steps.count-1), :class => "btn btn-small" do %>
    
    <% end %>

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

If you're using the block form of link_to you can't have text content (the block is your text content). You'd need to do this:

<%= link_to project_step_path(@project, @project.steps.count-1), :class => "btn btn-small" do %>
  Back
<% end %>

Typically this is used when you want to have images or other tags as the contents of the link. It's purely for display purposes. The block will not give you javascript-like functionality, so make sure additional display behavior is what you're looking for here :)

Solution 2 - Ruby on-Rails

If you pass a block then do not pass the link name. Should be:

<%= link_to project_step_path(@project, @project.steps.count-1), :class => "btn btn-small" do %>
  Back
<% end %>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionscientifficView Question on Stackoverflow
Solution 1 - Ruby on-RailsnzifnabView Answer on Stackoverflow
Solution 2 - Ruby on-RailsMarlin PierceView Answer on Stackoverflow