Thursday, December 13, 2012

[Rails] Re: make rails connect with database

class AnggotaController < ApplicationController
# GET /anggota
# GET /anggota.json
def index
@anggota = Anggotum.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @anggota }
end
end

# GET /anggota/1
# GET /anggota/1.json
def show
@anggotum = Anggotum.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @anggotum }
end
end

# GET /anggota/new
# GET /anggota/new.json
def new
@anggotum = Anggotum.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @anggotum }
end
end

# GET /anggota/1/edit
def edit
@anggotum = Anggotum.find(params[:id])
end

# POST /anggota
# POST /anggota.json
def create
@anggotum = Anggotum.new(params[:anggotum])

respond_to do |format|
if @anggotum.save
format.html { redirect_to @anggotum, notice: 'Anggotum was
successfully created.' }
format.json { render json: @anggotum, status: :created,
location: @anggotum }
else
format.html { render action: "new" }
format.json { render json: @anggotum.errors, status:
:unprocessable_entity }
end
end
end

# PUT /anggota/1
# PUT /anggota/1.json
def update
@anggotum = Anggotum.find(params[:id])

respond_to do |format|
if @anggotum.update_attributes(params[:anggotum])
format.html { redirect_to @anggotum, notice: 'Anggotum was
successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @anggotum.errors, status:
:unprocessable_entity }
end
end
end

# DELETE /anggota/1
# DELETE /anggota/1.json
def destroy
@anggotum = Anggotum.find(params[:id])
@anggotum.destroy

respond_to do |format|
format.html { redirect_to anggota_url }
format.json { head :no_content }
end
end
end

-------------------------------------------------------------

that the code of anggota_controller.rb
-----------------------------------------

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate