Skip to content

Commit

Permalink
view images
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferwills committed May 31, 2020
1 parent 9f7ba9a commit 4ca48e7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 31 deletions.
18 changes: 11 additions & 7 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def index
def show
end

# GET /images/new
def new
@image = Image.new
end

# GET /images/1/edit
def edit
Expand All @@ -24,7 +20,7 @@ def edit
# POST /images
# POST /images.json
def create
@image = Image.new(image_params)
@image = Image.new(create_params)

respond_to do |format|
if @image.save
Expand All @@ -41,7 +37,7 @@ def create
# PATCH/PUT /images/1.json
def update
respond_to do |format|
if @image.update(image_params)
if @image.update(update_params)
format.html { redirect_to @image, notice: 'Image was successfully updated.' }
format.json { render :show, status: :ok, location: @image }
else
Expand All @@ -68,10 +64,18 @@ def set_image
end

# Only allow a list of trusted parameters through.
def image_params
def create_params
params.require(:title)
params.require(:file)
params.require(:private)
params.permit(:title, :tags, :file, :private)
end

# Only allow a list of trusted parameters through.
def update_params
params.require(:title)
params.require(:private)
params.permit(:title, :tags, :private)
end

end
4 changes: 2 additions & 2 deletions app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class SiteController < ApplicationController
def home
@images = Image.where(private: false).find_each
@images = Image.find_each

end
def upload
end
def private
@images = Image.where(private: true).find_each
@images = Image.find_each

end
end
21 changes: 20 additions & 1 deletion app/views/images/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
<h1>Editing Image</h1>

<%= render 'form', image: @image %>
<%= form_with(url: image_path, method: "post", :html => {:class => "form-horizontal center"}) do |form| %>
<div class="form-group">
<%= form.label(:title, "Image Title:") %>
<%= form.text_field :title, :required => true %>
</div>
<div class="form-group">
<%= form.label(:tags, "Choose Tags:") %>
<%= form.text_field :tags%>
</div>
<div class="form-group">
<%= form.label(:private, "Make Picture Public:") %>
<%= form.check_box :private %>
</div>

<%= submit_tag("Upload") %>



<% end %>


<%= link_to 'Show', @image %> |
<%= link_to 'Back', images_path %>
25 changes: 22 additions & 3 deletions app/views/images/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
<p id="notice"><%= notice %></p>

<%= link_to 'Edit', edit_image_path(@image) %> |
<%= link_to 'Back', images_path %>
<div class="card-columns">

<div class="card">
<div class="card-block" >
<%= image_tag @image.file , :width => "100%" %>
<div class="card-body">
<p class="card-title"><%= @image.title %></p>

<% if @image.tags %>
<p class="card-subtitle mb-2 text-muted">Tags: <%= @image.tags %></p>
<% end %>

<%= link_to 'Edit', edit_image_path(@image) , :class => "btn btn-light"%>
<%= link_to 'Back', images_path , :class => "btn btn-light"%>


</div>

</div>

</div>
</div>
16 changes: 10 additions & 6 deletions app/views/site/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<h1>Public Images</h1>

<div class="card-columns">
<% @images.each do |img| %>
<div class="card">
<div class="card-block">
<%= image_tag img.file.variant(resize_to_limit: [100, 100]) %>
<div class="card-columns">
<% @images.each do |img| %>
<div class="card">
<div class="card-block" >
<%= image_tag img.file , :width => "100%" %>
<div class="card-body">
<p class="card-title"><%= img.title %></p>

<% if img.tags %>
<p class="card-subtitle mb-2 text-muted">Tags: <%= img.tags %></p>
<% end %>
Expand All @@ -14,8 +16,10 @@

</div>

</div>


<% end %>
<% end %>

</div>

Expand Down
12 changes: 4 additions & 8 deletions app/views/site/upload.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
<%= form_with(url: images_create_path, method: "post", :html => {:class => "form-horizontal center"}) do |form| %>
<div class="form-group">
<%= form.label(:file, "Choose File:") %>
<%= form.file_field :file, :required => true %>
<%= form.file_field :file, :required => true%>
</div>
<div class="form-group">
<%= form.label(:title, "Image Title:") %>
<div class="col-md-8">
<%= form.text_area :title, :required => true %>
</div>
<%= form.text_field :title, :required => true %>
</div>
<div class="form-group">
<%= form.label(:tags, "Choose Tags:") %>
<div class="col-md-8">
<%= form.text_area :tags %>
</div>
<%= form.text_field :tags%>
</div>
<div class="form-group">
<%= form.label(:private, "Make Picture Public:") %>
<%= form.check_box :private %>
</div>

<%= submit_tag("Upload") %>
<%= submit_tag("Upload", :class => "btn btn-primary") %>



Expand Down
5 changes: 1 addition & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
get 'site/home'
get 'site/upload'
get 'site/private'
get 'images/private'
get 'images/public'
get 'images/upload'
post 'images/create'

root to: 'site#home'
resources :users
# resources :images
resources :images
# get 'site/home'

# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
Expand Down

0 comments on commit 4ca48e7

Please sign in to comment.