"how to" show link to uploaded pdf file - newbie

Working with "attachment_fu" and have successfully uploaded a PDF file
via a form.
(File is located in /public/uploads/ )

I am having trouble "showing" the link to the file in the show page -
could someone show me some example code for the controller, model,view
etc... ?
The goal is to have a link to a PDF file associated with a blog entry.
Many thanks

Is it already linked to a post in the models? (pdf_file
belongs_to :post, post :has_one pdf_file)

of so, you can write...

post.pdf_file.public_filename

..to get the path to the uploaded file

Peter wrote:

Is it already linked to a post in the models? (pdf_file
belongs_to :post, post :has_one pdf_file)

of so, you can write...

post.pdf_file.public_filename

..to get the path to the uploaded file

On Mar 24, 8:50 pm, Liam Smith <rails-mailing-l...@andreas-s.net>

Here's the result (show.rhtml) of the code that I am trying to use.
Unfortunately it just shows the text string of the path and not the link
to the actual file.

.............
(localhost:3000/messages/12)

Title

Summary

Uploaded File : /uploads/0000/0010/test.pdf

Body text

.............

And here is the actual code.....

controller =

class MessagesController < ApplicationController

def index
    @title = "Messages"
    @messages = Messages.find(:all)

  end

  def create
    #Create the message
    @message = Message.new(params[:message])
    respond_to do |format|
      if @message.save

        if !params[:upload][:uploaded_data].blank?
          @message.upload = Upload.create(params[:upload])
        end
        flash[:notice] = 'File was successfully uploaded.'
        format.html { redirect_to :action=>'show', :id=>@message }
      else
        format.html { render :action => "new" }
      end
    end
  end

  def show
    @message = Message.find(params[:id])

    respond_to do |format|
      format.html # show.rhtml
      format.xml { render :xml => @message.to_xml }
    end
  end

  def update
      @message = Message.find(params[:id])
      respond_to do |format|
        if @message.update_attributes(params[:message])

          if !params[:upload][:uploaded_data].blank?
            #find current upload
            @upload = @message.upload ||= Upload.new
            @upload = @message.upload.build(params[:upload])
            @upload.save
          end
          format.html { redirect_to :action=>'show', :id=>@message }
        else
          format.html { render :action => "edit" }
        end
      end
    end

end

..........

message model =

class Message < ActiveRecord::Base
  has_one :upload, :conditions => 'parent_id is null'
  has_one :all_uploads, :class_name => 'Upload' # all attachments
end

showing the link is the problem?

<%= link_to 'Download', uploaded_file_path %>

Peter wrote:

showing the link is the problem?

<%= link_to 'Download', uploaded_file_path %>

On Mar 24, 10:20 pm, Liam Smith <rails-mailing-l...@andreas-s.net>

Yes, I am not understanding (sorry about this!) - how to code the
"uploaded_file_path" - how do I define this/where do I define this,
etc...?

that should be:

message.upload.public_filename

where message can be some message you find with Message.find
params[:id]

Peter wrote:

that should be:

message.upload.public_filename

where message can be some message you find with Message.find
params[:id]

On Mar 25, 12:16 am, Liam Smith <rails-mailing-l...@andreas-s.net>

FANTASTIC - THANK YOU for your help - very much appreciated!