Topic: Error link_to

Hi,

I am with a problem for render link_to.
Controller:

class TesteController < ApplicationController

    def index
        @users = User.all
    end

    def print_json
        user = User.find params[:id]
        respond_to do |format|
            format.json {render json: user}
        end
    end

end

View

<table border='1'>
  <tr>
    <th>ID</th>
    <th>NAME</th>
    <th>EMAIL</th>
  </tr>
  <% @users.each do |user| %>
  <tr>
    <td><%= user.id %></td>
    <td><%= user.name %></td>
    <td><%= user.email %></td>
    <td><%= link_to 'Print Json', print_json_path(user) %></td>
  </tr>
  <% end %>
</table>

when rails render my view, an error occurs informing that the method is missing.

someone can help me?

Re: Error link_to

check your routes to contain print_json root:

#in routes.rb 

...
match "whatever_you_want" => "test#print_json"

See more about routes at Rails guides: http://guides.rubyonrails.org/routing.html
You can always check the routes you have by running 'rake routes' in your terminal.

Last edited by Javix (2013-06-07 05:30:27)