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
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? %>