diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index b5ac8c9f..4569f380 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -1,83 +1,89 @@ -class PhotosController < ApplicationController - # GET /photos - # GET /photos.json - def index - @photos = Photo.all - - respond_to do |format| - format.html # index.html.erb - format.json { render json: @photos } - end - end - - # GET /photos/1 - # GET /photos/1.json - def show - @photo = Photo.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.json { render json: @photo } - end - end - - # GET /photos/new - # GET /photos/new.json - def new - @photo = Photo.new - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @photo } - end - end - - # GET /photos/1/edit - def edit - @photo = Photo.find(params[:id]) - end - - # POST /photos - # POST /photos.json - def create - @photo = Photo.new(params[:photo]) - - respond_to do |format| - if @photo.save - format.html { redirect_to @photo, notice: 'Photo was successfully created.' } - format.json { render json: @photo, status: :created, location: @photo } - else - format.html { render action: "new" } - format.json { render json: @photo.errors, status: :unprocessable_entity } - end - end - end - - # PUT /photos/1 - # PUT /photos/1.json - def update - @photo = Photo.find(params[:id]) - - respond_to do |format| - if @photo.update_attributes(params[:photo]) - format.html { redirect_to @photo, notice: 'Photo was successfully updated.' } - format.json { head :no_content } - else - format.html { render action: "edit" } - format.json { render json: @photo.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /photos/1 - # DELETE /photos/1.json - def destroy - @photo = Photo.find(params[:id]) - @photo.destroy - - respond_to do |format| - format.html { redirect_to photos_url } - format.json { head :no_content } - end - end -end +class PhotosController < ApplicationController + # GET /photos + # GET /photos.json + def index + @photos = Photo.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @photos } + end + end + + # GET /photos/1 + # GET /photos/1.json + def show + @photo = Photo.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @photo } + end + end + + # GET /photos/new + # GET /photos/new.json + def new + @photo = Photo.new + + @all_sites = Site.all + @all_projects = Project.all + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @photo } + end + end + + # GET /photos/1/edit + def edit + @photo = Photo.find(params[:id]) + + @all_sites = Site.all + @all_projects = Project.all + end + + # POST /photos + # POST /photos.json + def create + @photo = Photo.new(params[:photo]) + + respond_to do |format| + if @photo.save + format.html { redirect_to @photo, notice: 'Photo was successfully created.' } + format.json { render json: @photo, status: :created, location: @photo } + else + format.html { render action: "new" } + format.json { render json: @photo.errors, status: :unprocessable_entity } + end + end + end + + # PUT /photos/1 + # PUT /photos/1.json + def update + @photo = Photo.find(params[:id]) + + respond_to do |format| + if @photo.update_attributes(params[:photo]) + format.html { redirect_to @photo, notice: 'Photo was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @photo.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /photos/1 + # DELETE /photos/1.json + def destroy + @photo = Photo.find(params[:id]) + @photo.destroy + + respond_to do |format| + format.html { redirect_to photos_url } + format.json { head :no_content } + end + end +end diff --git a/app/models/photo.rb b/app/models/photo.rb index 849160e3..430b42ac 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -1,8 +1,12 @@ -class Photo < ActiveRecord::Base - belongs_to :imageable, :polymorphic => true - attr_accessible :copyright, :uri, :description - - validates :uri, :presence => true - validates_format_of :uri, :with => URI::regexp(%w(http https)) - validates :copyright, :presence => true -end +class Photo < ActiveRecord::Base + belongs_to :imageable, :polymorphic => true + attr_accessible :copyright, :uri, :description, :imageable_type, :imageable_id + + # http://stackoverflow.com/questions/6778269/rails-3-polymorphic-liking-of-entities-by-user-how + # http://stackoverflow.com/questions/746387/labels-for-radio-buttons-in-rails-form + validates :uri, :presence => true + validates_format_of :uri, :with => URI::regexp(%w(http https)) + validates :copyright, :presence => true + + +end diff --git a/app/views/photos/_form.html.erb b/app/views/photos/_form.html.erb index cf0643ad..328884d1 100644 --- a/app/views/photos/_form.html.erb +++ b/app/views/photos/_form.html.erb @@ -1,25 +1,40 @@ -<%= form_for(@photo) do |f| %> - <% if @photo.errors.any? %> -
Uri | -Copyright | -- | - | - |
---|---|---|---|---|
<%= photo.uri %> | -<%= photo.copyright %> | -<%= link_to 'Show', photo %> | -<%= link_to 'Edit', edit_photo_path(photo) %> | -<%= link_to 'Destroy', photo, method: :delete, data: { confirm: 'Are you sure?' } %> | -
Uri | +Copyright | +Description | +Ref Id | +Ref Table | ++ | + | + |
---|---|---|---|---|---|---|---|
<%= photo.uri %> | +<%= photo.copyright %> | +<%= photo.description %> | +<%= photo.imageable_id %> | +<%= photo.imageable_type %> | +<%= link_to 'Show', photo %> | +<%= link_to 'Edit', edit_photo_path(photo) %> | +<%= link_to 'Destroy', photo, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
- -- Uri: - <%= @photo.uri %> -
- -- Copyright: - <%= @photo.copyright %> -
- - -<%= link_to 'Edit', edit_photo_path(@photo) %> | -<%= link_to 'Back', photos_path %> +<%= notice %>
+ ++ Uri: + <%= @photo.uri %> +
+ ++ Copyright: + <%= @photo.copyright %> +
+ ++ Description: + <%= @photo.description %> +
+ ++ Parent: + <%= @photo.imageable %> +
+ +<%= link_to 'Edit', edit_photo_path(@photo) %> | +<%= link_to 'Back', photos_path %> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index dec17cf3..1d2bc866 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -1,29 +1,35 @@ -<%= notice %>
- -- Name: - <%= @project.name %> -
- -- Description: - <%= @project.description %> -
- -- Urn: - <%= @project.urn %> -
- -- Notes: - <%= @project.notes %> -
- -- Sites: - <%= @project.sites %> -
- -<%= link_to 'Edit', edit_project_path(@project) %> | -<%= link_to 'Back', projects_path %> +<%= notice %>
+ ++ Name: + <%= @project.name %> +
+ ++ Description: + <%= @project.description %> +
+ ++ Urn: + <%= @project.urn %> +
+ ++ Notes: + <%= @project.notes %> +
+ ++ Sites: + <%= @project.sites %> +
+ ++ Photos: + <%= @project.photos %> +
+ + +<%= link_to 'Edit', edit_project_path(@project) %> | +<%= link_to 'Back', projects_path %> diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index 2ab56d97..5eab39c6 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -1,25 +1,29 @@ -<%= notice %>
- -- Name: - <%= @site.name %> -
- -- Latitude: - <%= @site.latitude %> -
- -- Longitude: - <%= @site.longitude %> -
- -- Notes: - <%= @site.notes %> -
- - -<%= link_to 'Edit', edit_site_path(@site) %> | -<%= link_to 'Back', sites_path %> +<%= notice %>
+ ++ Name: + <%= @site.name %> +
+ ++ Latitude: + <%= @site.latitude %> +
+ ++ Longitude: + <%= @site.longitude %> +
+ ++ Notes: + <%= @site.notes %> +
+ ++ Photos: + <%= @site.photos %> +
+ +<%= link_to 'Edit', edit_site_path(@site) %> | +<%= link_to 'Back', sites_path %>