Skip to content

Commit

Permalink
Merge pull request #3 from XiaoA/setup-models
Browse files Browse the repository at this point in the history
Set up models
  • Loading branch information
XiaoA authored Jul 5, 2022
2 parents 09adce7 + 84560e3 commit 02ebd12
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
PATH
remote: ../rulers
specs:
rulers (0.1.1)
rulers (0.1.2)
erubis (~> 2.7.0)
multi_json (= 1.15.0)
rack (~> 2.2.4)

GEM
Expand All @@ -13,6 +14,7 @@ GEM
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
multi_json (1.15.0)
nio4r (2.5.8)
puma (5.6.4)
nio4r (~> 2.0)
Expand Down
42 changes: 42 additions & 0 deletions app/controllers/quotes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
class QuotesController < Rulers::Controller

def index
quotes = FileModel.all
render :index, :quotes => quotes
end

def new_quote
attrs = {
"submitter" => "web user",
"quote" => "A picture is worth a thousand pixels",
"attribution" => "Me"
}

m = FileModel.create attrs
render :quote, :obj => m
end

def a_quote
render :a_quote, :noun => :thinking
end

def quote_1
quote_1 = FileModel.find(1)
render :quote, :obj => quote_1
end

def update
raise "Only POST to this route!" unless
env["REQUEST_METHOD"] == "POST"
body = env["rack.input"].read
astr = body.split("&")
params = {}
astr.each do |a|
name, val = a.split "="
params[name] = val
end

quote = FileModel.find(params["id"].to_i)
quote["submitter"] = params["submitter"]
quote.save

rander :quote, :obj => quote
end

def exception
raise "It's a bad one!"
end


end


4 changes: 4 additions & 0 deletions app/views/quotes/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% quotes.each do |quote| %>
<p> <%= quote["quote"] %> </p>
<% end %>

9 changes: 9 additions & 0 deletions app/views/quotes/quote.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>
&quot;<%= obj["quote"] %>&quot;
<br />
&ndash; <%= obj["attribution"] %>
</p>

</p>
Submitted by <%= obj["submitter"] %>
</p>
5 changes: 5 additions & 0 deletions db/quotes/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"submitter": "Andrew",
"quote": "A penny saved is a penny earned.",
"attribution": "Ben Franklin"
}
5 changes: 5 additions & 0 deletions db/quotes/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"submitter": "web user",
"quote": "A picture is worth a thousand pixels",
"attribution": "Me"
}
5 changes: 5 additions & 0 deletions db/quotes/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"submitter": "web user",
"quote": "A picture is worth a thousand pixels",
"attribution": "Me"
}
5 changes: 5 additions & 0 deletions db/quotes/4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"submitter": "web user",
"quote": "A picture is worth a thousand pixels",
"attribution": "Me"
}
5 changes: 5 additions & 0 deletions db/quotes/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"submitter": "web user",
"quote": "A picture is worth a thousand pixels",
"attribution": "Me"
}

0 comments on commit 02ebd12

Please sign in to comment.