-
-
Save ratnikov/925729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Scaffolded, because it's realy straight forward ;-) | |
# | |
class BlogpostsController < ApplicationController | |
before_filter :authenticate_admin! , :except => [:index, :show] | |
# GET /blogposts | |
# GET /blogposts.xml | |
def index | |
@blogposts = Blogpost.all | |
@title = "Photo Blog" | |
respond_to do |format| | |
format.html { | |
@blogposts = Blogpost.order(:title).page(params[:page]).per(5) | |
} # index.html.erb | |
format.xml { | |
@blogposts = Blogpost.all | |
render :xml => @blogposts | |
} | |
format.atom { | |
@blogposts = Blogpost.all | |
} | |
end | |
end | |
# GET /blogposts/1 | |
# GET /blogposts/1.xml | |
def show | |
@blogpost = Blogpost.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.xml { render :xml => @blogpost } | |
end | |
end | |
# GET /blogposts/new | |
# GET /blogposts/new.xml | |
def new | |
@blogpost = Blogpost.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.xml { render :xml => @blogpost } | |
end | |
end | |
# GET /blogposts/1/edit | |
def edit | |
@blogpost = Blogpost.find(params[:id]) | |
end | |
# POST /blogposts | |
# POST /blogposts.xml | |
def create | |
@blogpost = Blogpost.new(params[:blogpost]) | |
respond_to do |format| | |
if @blogpost.save | |
format.html { redirect_to(@blogpost, :notice => 'Blogpost was successfully created.') } | |
format.xml { render :xml => @blogpost, :status => :created, :location => @blogpost } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @blogpost.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /blogposts/1 | |
# PUT /blogposts/1.xml | |
def update | |
@blogpost = Blogpost.find(params[:id]) | |
respond_to do |format| | |
if @blogpost.update_attributes(params[:blogpost]) | |
format.html { redirect_to(@blogpost, :notice => 'Blogpost was successfully updated.') } | |
format.xml { head :ok } | |
else | |
format.html { render :action => "edit" } | |
format.xml { render :xml => @blogpost.errors, :status => :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /blogposts/1 | |
# DELETE /blogposts/1.xml | |
def destroy | |
@blogpost = Blogpost.find(params[:id]) | |
@blogpost.destroy | |
respond_to do |format| | |
format.html { redirect_to(blogposts_url) } | |
format.xml { head :ok } | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml ...?> | |
<% @posts.each do |post| -%> | |
<post> | |
<title><%= post.title %></title> | |
<content> | |
<%= render :partial => '...' %> | |
</content> | |
</post> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment