#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    8
    Rep Power
    0

    Displaying an image


    I am trying to display an image that is in my public/image folder and I
    don't know how to.

    What I want to do is to be able to assign a photo to an artist so you
    can navigate through different artist's photo.

    This is my image model

    Code:
    class Image < ActiveRecord::Base
      has_many :publishings
      has_many :artists, :through => :publishings
      has_many :comments,:through => :friends
    
      has_many :comments, :as => :resource, :class_name => "Commentable"
    end
    This is my image show.html

    Code:
    <p id="notice"><%= notice %></p>
    
    <p>
      <b>Title:</b>
      <%= @image.title %>
    </p>
    
    <p>
      <b>Filename:</b>
      <%= @image.filename %>
    </p>
    
    <p>
      <b>Likes:</b>
      <%= @image.likes %>
    </p>
    
    
    <%= link_to 'Edit', edit_image_path(@image) %> |
    <%= link_to 'Back', images_path %>
    This is the database for images

    Code:
    class CreateImages < ActiveRecord::Migration
      def self.up
        create_table :images do |t|
          t.string :title :null => false
          t.string :filename :null =>false
          t.integer :likes :default =>0
    
          t.timestamps
        end
      end
    
      def self.down
        drop_table :images
      end
    end
    Thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    83
    Rep Power
    39
    You can get the relative URL for an image using image_path(filename). You can also use the image_tag helper, which generates an img tag with its src attribute containing the URL for the given file name.

IMN logo majestic logo threadwatch logo seochat tools logo