0

I want to display a particular image on my landing page that I have uploaded through the dragonfly gem.

I am getting following error: param is missing or the value is empty: photo

this is what I have on my landing.html.erb view:

<%= image_tag @photo.1.image.thumb('150x185#').url if @photo.1.image_stored? %>

this is what I have on my pages controller:

class PagesController < ApplicationController

    def landing
        @photo = Photo.find(photo_params)
    end


    def photo_params
      params.require(:photo).permit(:image)
    end

end

How do I pass an id of 1 to my @photo object? I know this might be a newb question but I have spent several hours trying different things and nothing has worked. Thanks!

These are my routes:

  root 'pages#landing'

  match '/home',    to: 'pages#home',    via: 'get'
  match '/about',   to: 'pages#about',     via: 'get'
  match '/gallery',   to: 'pages#gallery',   via: 'get'

  match '/events',   to: 'pages#events',   via: 'get'
  match '/menu',   to: 'pages#menu',   via: 'get'
  match '/testing',   to: 'pages#testing',   via: 'get'
  match '/contacts',     to: 'contacts#new',             via: 'get'
  resources "contacts", only: [:new, :create]
  match '/events',   to: 'pages#mevents',   via: 'get'
  resources "events", only: [:new, :create]

  resources :photos
user3597950
  • 9,201
  • 6
  • 26
  • 35
  • It's hard to tell what you're after here... Does `@photo = Photo.find(params[:id])` work? Maybe put your relevant route and how you are calling it... – Brad Werth Aug 29 '14 at 04:25
  • @BradWerth what do you mean it's hard to tell what I am after? I am trying to the the photo with id = 1 hence the [at]photo.1 portion of the code. This seems to be the incorrect format though... – user3597950 Aug 29 '14 at 04:54
  • I mean that your question is difficult to parse, your intention is unclear, and key elements seem to be omitted from the question. I believe I am no alone in this opinion, as evidenced by your close vote and lack of response. Please keep in mind that I am not trying to be rude, but rather offer constructive criticism that will further illuminate your issue. I would like very much to answer this, but it feels incomplete... – Brad Werth Aug 29 '14 at 04:59
  • @BradWerth sorry if it seems incomplete. I am new to coding and that is probably the reason. I don't know what it is that I don't know if that makes any sense... I am not sure what more information I could add... – user3597950 Aug 29 '14 at 05:07
  • No worries. As I originally suggested, I believe including the relevant route to `pages#landing` as well as the link you are using to arrive there would be helpful. – Brad Werth Aug 29 '14 at 05:19
  • @BradWerth I've edited my question to include my routes file, not sure if there is anything that will help there but let me know if you spot something! thanks. – user3597950 Aug 29 '14 at 05:36
  • Are you trying specifically to get literally `1`, or are you hoping to make that value dynamic? – Brad Werth Aug 29 '14 at 05:43
  • @BradWerth I want to specifically get 1 – user3597950 Aug 29 '14 at 05:46

1 Answers1

0

There are some issues with this code.

First, the route does not pass any attributes to the method that you can use to determine the desired photo. Secondly, you are not submitting a form that would provide the photos params in your photo_params method. Luckily, you do not need it to be dynamic, so you can simply remove that portion. Finally, you can not simply add the desired id to the method chain in the instance variable (once you get it). Try adjusting your code to look more like this:

class PagesController < ApplicationController

  def landing
    @photo = Photo.find(1)
  end

end

and

<%= image_tag( @photo.image.thumb('150x185#').url ) if @photo.image_stored? %>
Brad Werth
  • 17,411
  • 10
  • 63
  • 88