Skip to content

Instantly share code, notes, and snippets.

@andrellima
Created March 26, 2011 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrellima/888236 to your computer and use it in GitHub Desktop.
Save andrellima/888236 to your computer and use it in GitHub Desktop.
<%= form_for (@gallery, :html => {:multipart => true}) do |f| %>
<% if @gallery.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@gallery.errors.count, "error") %> prohibited this gallery from being saved:</h2>
<ul>
<% @gallery.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<%= f.fields_for :gallery_photos do |gf_form| %>
<%= gf_form.label :photo, 'Photo:' %>
<%= gf_form.file_field :photo %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
class GalleriesController < ApplicationController
# GET /galleries
# GET /galleries.xml
layout "admin"
def index
@galleries = Gallery.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @galleries }
end
end
# GET /galleries/1
# GET /galleries/1.xml
def show
@gallery = Gallery.find(params[:id])
@gallery_photo = @gallery.gallery_photos.find(params[:all])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @gallery }
end
end
# GET /galleries/new
# GET /galleries/new.xml
def new
@gallery = Gallery.new
@gallery_photos = @gallery.gallery_photos.build
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @gallery }
end
end
# GET /galleries/1/edit
def edit
@gallery = Gallery.find(params[:id])
end
# POST /galleries
# POST /galleries.xml
def create
@gallery = Gallery.new(params[:gallery])
gallery_photo = GalleryPhoto.new
gallery_photo = GalleryPhoto.find(:all, :conditions => {:gallery_id => @gallery.id})
respond_to do |format|
if @gallery.save
format.html { redirect_to(@gallery, :notice => 'Gallery was successfully created.') }
format.xml { render :xml => @gallery, :status => :created, :location => @gallery }
else
format.html { render :action => "new" }
format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity }
end
end
end
# PUT /galleries/1
# PUT /galleries/1.xml
def update
@gallery = Gallery.find(params[:id])
respond_to do |format|
if @gallery.update_attributes(params[:gallery])
format.html { redirect_to(@gallery, :notice => 'Gallery was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @gallery.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /galleries/1
# DELETE /galleries/1.xml
def destroy
@gallery = Gallery.find(params[:id])
@gallery.destroy
respond_to do |format|
format.html { redirect_to(galleries_url) }
format.xml { head :ok }
end
end
end
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<%= @gallery.name %>
</p>
<%= image_tag @gallery_photo.photo.url(:medium) %>
<%= link_to 'Edit', edit_gallery_path(@gallery) %> |
<%= link_to 'Back', galleries_path %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment