Question

ruby on rails sinatra require 'sinatra' require 'data_mapper' DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/dogs.db") class Dog    include DataMapper::Resource   ...

ruby on rails sinatra

require 'sinatra'
require 'data_mapper'

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/dogs.db")

class Dog
   include DataMapper::Resource
   property :id, Serial
   property :name, Text
   property :breed, Text
   property :weight, Integer
end

DataMapper.finalize
Dog.auto_upgrade!

#display the name and breed and weight of every dog
get '/dogs' do
  
end

#create a new dog
post '/dogs' do
  
end

#update an existing dog, given its id and new information
patch '/dogs' do
  
end

#delete a dog, given its id
delete '/dogs' do

end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

require 'sinatra'
require 'data_mapper'

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/dogs.db")

class Dog
   include DataMapper::Resource
   property :id, Serial
   property :name, Text
   property :breed, Text
   property :weight, Integer
end

DataMapper.finalize
Dog.auto_upgrade!

#display the name and breed and weight of every dog
get '/dogs' do

@dogs = Dog.all

erb :index
end

#create a new dog
post '/dogs' do
@dog = Dog.new(params[:dog])

@dog.save

redirect '/dogs'
end

#update an existing dog, given its id and new information
patch '/dogs/:id' do
  @dog = Dog.find(params[:id])

@dog.update(params[:dog])

redirect “/@dog.id”>dogs/#{@dog.id}”
end

#delete a dog, given its id
delete '/dogs.:id' do

   @dog = Dog.find(params[:id])

@dog.destoy

redirect '/dogs'

end

Add a comment
Know the answer?
Add Answer to:
ruby on rails sinatra require 'sinatra' require 'data_mapper' DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/dogs.db") class Dog    include DataMapper::Resource   ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please, please help with C program. This is a longer program, so take your time. But...

    Please, please help with C program. This is a longer program, so take your time. But please make sure it meets all the requirements and runs. Here is the assignment: I appreciate any help given. Cannot use goto or system(3) function unless directed to. In this exercise you are to create a database of dogs in a file, using open, close(), read, write(), and Iseek(). Do NOT use the standard library fopen() ... calls! Be sure to follow the directions!...

  • RE-POSTED - Computer Science staff, I need this question answered. It will determine a pass or...

    RE-POSTED - Computer Science staff, I need this question answered. It will determine a pass or a fail. Its very imortant that this and the other questions posted are answered 100% Thank you. 13 - Template C++ Advance Please Only answer assignment if your code is 100%. When pasteing your code use text so I may copy and paste into visual studio. The code and questions must be answered 100% correct and works. Thank you. Programming Assignment Convert the int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT