views:

33

answers:

1

Hi @all, i'm having a no route matches error after a render :partial

<% unless @user.uploads.empty? %>
 <% @user.uploads.each do |u| %>
 <tr>
 <td><%= link_to u.filename, u.filename %></td>

it gives me the right filename like http://localhost:3000/DSC00082.JPG. i haven't added anything to my routes. for being new to rails, please excuse my (hopefully) easy question.

to add a question: is it right for the corresponding database entry to be just the filename?

after changing above code to

<% unless @user.uploads.empty? %>
 <% @user.uploads.each do |uploads| %>
 <tr>
 <td><%= link_to (uploads.filename, uploads) %></td>

and adding map.rescources :upload, a "No action responded to show" message was generated. in the adress bar, my browser shows the id of the regarding dataset.

Greetings, devyn

A: 

If u is a subclass of ActiveRecord::Base, your link_to has to be like this:

<%= link_to u.filename, u %>

The same Rails would detect that u is an object with controller, and it will convert it to a REST valid URL (and redirect you to the show action).

If this isn't your scenario, please tell me.

[EDIT]

If you know how Rails work, skip this paragraph:

With map.resources :upload you are telling rails that you have a resource called Upload that has a UploadController, and generates routes for 5 actions: new/create, index, show, edit/update and destroy. Each action needs a method in the controller(See the ClientsController example in Rails Guides).

"No action responded to show" raises when you don't have UploadsController#show. An example of this method:

def show
  @upload = Upload.find(params[:id])
  respond_to do |format|
    format.html
    format.xml {render :xml => @upload}
  end
end

This method render a the file views/uploads/show (be sure of create it).

pablorc
unfortunately, this throws an "undefined method `upload_path'" message; even after changing all regarding "u" to "upload(s)".
devyn furthermore
Your config/routes.rb has the line " map.resources :uploads " (Without the quotes) ?
pablorc
please see edited post above. it has to be rescources :upload for my controller is named that way
devyn furthermore
I edited my answer, too :)
pablorc