In my web app each album has many photos and each photo belongs to an album. I have already done the associations along with the new and create actions for photos and I am not getting an error, however, when I go to the albums show actions the newly created photos are not appearing.
View:
<% @photos.each do |x| %>
<div class="new-photo">
<%= image_tag x.image, :style => "height:200px; width:200px; border-radius:5px;" %>
</div>
<% end %>
Albums controller:
def show
@album = current_user.albums.find(params[:id])
@photos = @album.photos
@interests = current_user.interests
end
Photos controller:
def new
@photo = current_user.photos.new
end
def create
@photo = current_user.photos.new(photo_params)
if @photo.save
redirect_to '/albums'
else
render '/photos/new'
end
end
private
def photo_params
params.require(:photo).permit(:image)
end
Photo Model:
class Photo < ActiveRecord::Base
belongs_to :album
belongs_to :user
end
Album model:
class Album < ActiveRecord::Base
belongs_to :user
has_many :photos
end