Reputation: 45
I have set everything up for active storage and when I add a trip with an image, the app redirects to that trips show page and I can see the image. When I lave and go back to that show page I get the error
`Can't resolve image into URL: undefined method `persisted?' for nil:NilClass`
Here is the show page for trip
<h1> Location: <%= @trip.location %> </h1>
<h2> Date Visited: <%= @trip.date %> </h2>
<%= image_tag @trip.cover_photo, :style => "max-height:300px"%>
<h2> More Photos </h2>
<%= link_to "Add a photo", new_photo_path(@trip) %> <br>
<%= link_to "Public Profile", trips_path(@user) %> <br>
Here is the new trip form
<h1>Add a new trip </h1>
<%= form_for @trip do |f| %>
<%= f.label :location %>
<%= f.text_field :location %> <br>
<%= f.label :date %>
<%= f.text_field :date %> <br>
<%= f.label :cover_photo %>
<%= f.file_field :cover_photo %> <br>
<%= f.hidden_field :user_id, :value => session[:user_id] %>
<%= f.submit "Submit" %>
<% end %>
I'm not able to see the error since the photo uploads and displays correctly at first.
Upvotes: 4
Views: 2445
Reputation: 579
Had the same issue, except that I wasn't able to display the images even once. In your case, seems that the first time you are watching a temporal image, which is deleted after you live that view.
I realize that I was forgetting to add the attachment to permitted parameters in my controller, so the image wasn't saving. Your params should look like this:
def trip_params
params.require(:trip).permit(:location, :date, :cover_photo, :user_id)
end
Upvotes: 3