Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6361639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:48:14+00:00 2026-05-24T23:48:14+00:00

<% @company.comments.each do |comment| %> <tr> <td><%= comment.commenter %></td> <td><%= comment.body %></td> <td><%= time_ago_in_words(comment.created_at,

  • 0
<% @company.comments.each do |comment| %>
  <tr>
    <td><%= comment.commenter %></td>
    <td><%= comment.body %></td>
    <td><%= time_ago_in_words(comment.created_at, "Comment") %> ago</td>
    <td><%= comment.commentfile %></td>
  </tr>
<% end %>

Is where i am trying to display the uploaded file from the form below:

<h2>Add a comment:</h2>
<%= form_for([@company, @company.comments.build]) do |f| %>
  <div class="hidden">
    Name:<br />
    <%= f.text_field :commenter, :value => current_user.full_name, :readonly => "readonly" %>
  </div>
  <div class="field">
    Comment:<br />
    <%= f.text_area :body %>
  </div>
  <div class="field">
    <%= f.file_field :commentfile %>  
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

but I don’t know whether the file is being saved beacause when i check my public/uploads folder no files appear. And in the view at <%= comment.commentfile %> I get the name of the file i uploaded but no idea where the file is or how i can link to it or whether the file even uploaded at all? starting to think it just inserted a string. My model below.

class Comment < ActiveRecord::Base
  belongs_to :contact
  belongs_to :company
  mount_uploader :commentfile, CommentFileUploader
end

and comment_file_uploader.rb

class CommentFileUploader < CarrierWave::Uploader::Base

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

Please help!

Also to note if i do

u = Comment.new
u.commentfile = params[:file]

in console i get

NameError: undefined local variable or method `params' for main:Object

The migration adding :commentfile

class CreateUploader < ActiveRecord::Migration
  def self.up
    add_column :comments, :commentfile, :string
  end

  def self.down
  end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:48:14+00:00Added an answer on May 24, 2026 at 11:48 pm

    The browser has to use a special format to post the upload file data with the form data. You need to make the form multipart.

    <%= form_for( [@company, @company.comments.build],
                  :html => { :multipart => true } ) do |f| %>
    

    This adds the attribute enctype=”multipart/form-data” to the generated HTML, and the browser should then be able to send the uploaded file in a separate part of the message.

    If you use Firebug or similar to examine the post data, you’ll see that without the multipart encoding enabled, the browser just doesn’t send the file data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to institute code reviews at my company, and recently we had
We are currently trying to mavenize the existing projects in our company. We have
Many corporate coding standards require a large comment header and footer in each and
My route: scope /ajax do resources :companies do resources :comments end end So, link_to
class CommentsController < ApplicationController def create @contact = Contact.find(params[:contact_id]) @comment = @contact.comments.create(params[:comment]) respond_to do
My company is using CVS as our de-facto standard for source control. However, I've
My company has developed a long standing product using MFC in Visual C++ as
Our company is currently writing a GUI automation testing tool for compact framework applications.
The company I used to work with has two developers working fulltime, and a
The company I work for makes hardware that communicates to the computer though a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.