Member Route error "No action responded to"

Problem:

Member routes allow one to create additional routes to existing resources. For example, if you want to add an approve path to your purchases resource, you could do this in your config/routes.rb:

 map.resources :purchases, :member => { :approve => :put }

My problem was that the link I made for approving the purchase

<%= link_to "Approve Purchase", approve_purchase_path(@purchase), :confirm => "Proceed with approval?" %>

resulted in the following error:

Unknown action

No action responded to 1. Actions: approve, create, destroy, edit, index, new, show, and update

Cause:

Rails confused the link with a normal get operation.

Solution:

Explicitly declare the HTTP method for the action.

<%= link_to "Approve Purchase", approve_purchase_path(@purchase), :confirm => "Proceed with approval?", :method => :put %>

HTML Line Breaks in Rails Text Fields

Problem:

Rails doesn’t automatically convert newline (“\n“) characters in strings to line breaks (“<br>“) with h.

<%= h @user.address %>

Solution:

Manually replacing the \n with <br> without using h will make your site vulnerable to XSS attacks. The proper approach would be to convert the line breaks after h. Note that Rails already has a method, simple_format, that converts line breaks.

<%= simple_format(h @user.address) %>