Skip to content

In order to ease extra code needed to process different formats of URLs restful_additions is to the rescue.

Notifications You must be signed in to change notification settings

copypastel/restful_additions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Restful Additions

Restful Additions is an attempt to give services access to data without sacrificing the human friendly URLs.

I lost the copy I was working on so thought I better post this backup, I believe restful_find works but not in all of the cases below.

What it does...

Best for now is probably by example.

List of all posts paginated

Display of my post

Display of my post

List of all of my posts paginated

Display of my post

Display of my first post (notice it isn't 4 like the post id)

List of all of my posts paginated

Display of my post How it does it...

class PostsController < ApplicationController
  def index
    @posts = request.records_for_page
  end

  def show
    @post = request.record
  end

  def new
    @post = request.new_record
  end

  def edit
    @post = request.record
  end

  def create
    @post = request.new_record  #Actually creates the record with the params in mind

    if @post.save then flash[:notice] = 'Post was successfully created.'
    else                      flash[:error]   = @post.errors; end
  end

  def update
   @post = request.update_record
    if(@post.valid?) then flash[:notice] = 'Post was successfully updated.'
    else                        flash[:error]    = @post.errors ; end
  end

  def destroy
    @post = request.destroy_record
  end
end

#Models
class Post < ActiveRecord::Base
  restful_key :url_title
  restful_key :id
 
  belongs_to :author, :class_name => "Member"
end

class Member < ActiveRecord::Base
  has_many :posts
end

#and lastly routes
map.resources :posts
map.resources :members, :has_many => [:posts]

About

In order to ease extra code needed to process different formats of URLs restful_additions is to the rescue.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages