@members = Member.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @members }
end
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※indexメソッド
def index
@members = Member.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @members }
end
end
※new/createメソッド
def new
@member = Member.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @member }
end
end
def create
@member = Member.new(params[:member])
respond_to do |format|
if @member.save
format.html { redirect_to @member, notice: 'Member was successfully created.' }
format.json { render json: @member, status: :created, location: @member }
else
format.html { render action: "new" }
format.json { render json: @member.errors, status: :unprocessable_entity }
end
end
end
※edit/updateメソッド
def edit
@member = Member.find(params[:id])
end
def update
@member = Member.find(params[:id])
respond_to do |format|
if @member.update_attributes(params[:member])
format.html { redirect_to @member, notice: 'Member was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @member.errors, status: :unprocessable_entity }
end
end
end
※destroyメソッド
def destroy
@member = Member.find(params[:id])
@member.destroy
respond_to do |format|
format.html { redirect_to members_url }
format.json { head :no_content }
end
end
| << 前へ |