I have a controller that I want to have 2 responses, the generic html and the json. In my view, I want to have a link to said json. I saw in the apidoc, someone said you accomplish designating the format in the link_to by doing somethin like this.
<h3><%= link_to "Indexes" ,
params.merge({:format => "json"}) ,
state_laws_path %></h3>
However, everytime I visit the page this link is located on ( state_laws/index.html.erb ) I get the following error.
undefined method `stringify_keys' for "/state_laws":String
Extracted source (around line #3):
1: <h2>State Laws</h2>
2: <h3><%= link_to "Create State Law", new_state_law_path %></h3>
3: <h3><%= link_to "Indexes" ,
params.merge({:format => "json"}) ,
state_laws_path %> </h3>
4: <ul id="state_laws">
5: <% @state_laws.each do |law| %>
6: <li class="<%= cycle("odd", "even") %>">
Does anyone have any ideas of how I can tell my view that I want a link that will go to the index action of the controller using the json format ? Any help is greatly appreciated.