mardi 17 novembre 2015

Masking Links in Rails

I'm currently trying to mask a link within my rails application as it's linking out to different websites. I'll explain a simple scenario below:

Currently when hovering a link I get

http://ift.tt/1X5LUIa

I'm trying to make it show

http://ift.tt/1PyLIC6

I'm using a basic rails scaffold set-up with friendly_id on my models. I've asked this before but it's giving me errors. Please see code below.

The Error

PG::UndefinedColumn: ERROR: column offers.friendly_id does not exist LINE 1: SELECT "offers".* FROM "offers" WHERE "offers"."friendly_id... ^ : SELECT "offers".* FROM "offers" WHERE "offers"."friendly_id" IS NULL LIMIT 1

offers_controller.rb

# GET /offers/1.json
  def show
    link = Offer.find_by!(friendly_id: params[:slug])
    redirect_to link.url
  end

routes.rb

get "offers/:slug", to: "offers#show"

offer.rb

class Offer < ActiveRecord::Base
    belongs_to :category
  validates :category, presence: true

  extend FriendlyId
  friendly_id :title, use: :slugged

  mount_uploader :merchantImg, MerchantImgUploader
  mount_uploader :image, ImageUploader
end

Any help would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire