Skip to content

Instantly share code, notes, and snippets.

@px-amaac
Last active August 29, 2015 14:05
Show Gist options
  • Save px-amaac/76f391075cdd4a677471 to your computer and use it in GitHub Desktop.
Save px-amaac/76f391075cdd4a677471 to your computer and use it in GitHub Desktop.
<p>
<%= form_for([@photo, @tag]) do |f| %>
<div class="field">
<%= f.label :key %>
<%= f.text_field :key %>
</div>
<div class="field">
<%= f.label :value %>
<%= f.text_field :value %>
</div>
<%= f.submit "Tag Photo", class: "button success" %>
<% end %>
</p>
class HomeController < ApplicationController
def index
@user = current_user
@photos = Photo.all
end
end
<h1>All Photos</h1>
<div class="row">
<% @photos.each do |photo| %>
<div class "row">
<h2> <%= photo.title %> </h2>
<% if user_signed_in? && photo.user_id == current_user.id %>
<%= link_to image_tag(photo.image.url(:thumb)), photo_path(photo) %>
////////////////////I need the form here?????????????????????????????????????
<%= link_to 'Destroy', photo, method: :delete, data: { confirm: 'Are you sure?' }, :class => "button alert" %>
<% else %>
<%= image_tag(photo.image.url(:thumb)) %>
<% end %>
</div>
<% end %>
</div>
Rails.application.routes.draw do
get "tag/create"
get 'home/index'
root :to => 'home#index'
resources :photos do
resources :tags, only: [:create, :destroy]
end
devise_for :users
class TagsController < ApplicationController
before_action :set_photo, only: [:create]
def create
@tag = @photo.tags.build(tag_params)
if @tag.save
flash[:success] = "Photo Tagged"
redirect_to @photo
end
end
private
def set_photo
@photo = current_user.photos.find_by( id: params [:photo_id])
redirect_to root_url if @photo.nil?
end
def tag_params
params.require(:tag).permit(:id, :key, :value)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment