Skip to content

Codespace probable funicular v6gqwgx76w6v3w6vr #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/misc_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class MiscController < ApplicationController
def homepage
render({ :template => "misc_templates/home"})
end
end
13 changes: 13 additions & 0 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class PhotosController<ApplicationController
def list
@photos_list = Photo.all.order({:created_at=>:desc})
render({ :template => "photo_templates/list" })
end

def show
the_id=params.fetch("path_id")
@the_photo=Photo.where(:id=>the_id).at(0)
render({ :template => "photo_templates/show" })
end

end
33 changes: 33 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class UsersController<ApplicationController
def list
@user_list = User.all.order({:created_at=>:desc})
render({ :template => "user_templates/list" })
end
def insert
@new_user=User.new
@new_user.username=params.fetch("username")
# if @new_user.valid?
@new_user.save
redirect_to("/users", { :notice => "Actor created successfully." })
# else
# redirect_to("/users")
# end
end

def edit
the_username=params.fetch("path_id")
@the_user=User.where({:username=>the_username}).at(0)
@the_user.username=params.fetch("username")
@the_user.save
redirect_to("/users/#{@the_user.username}", { :notice => "Actor created successfully." })

end

def show
the_id=params.fetch("path_id")
@the_user=User.where(:username=>the_id).at(0)
render({ :template => "user_templates/show" })
end


end
6 changes: 5 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
</head>

<body>

<nav>
<ul>
<li><a href="/users">Users</a></li>
<li> <a href="/photos">Photos</a></li>
</ul>
<%= yield %>
</body>
</html>
Empty file.
33 changes: 33 additions & 0 deletions app/views/photo_templates/list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h1>List of photos</h1>

<form action="/add_photo" method="post">
<label for="url_box">Name</label>
<input type="text" id="url_box" name="url" placeholder="Enter a URL for the image">

<label for="caption_box">Name</label>
<input type="text" id="caption_box" name="caption" placeholder="Enter a caption for the photo">

<label for="owner_id_box">Name</label>
<input type="text" id="owner_id_box" name="owner_id" placeholder="Enter an ID of a user">

<button>Add photo</button>
</form>

<table border=1>
<tr>
<th>Image</th>
<th>Owner</th>
<th>Caption</th>
<th>Posted</th>
<th></th>
</tr>
<%@photos_list.each do |a_picture|%>
<tr>
<td><img src="<%= a_picture.image%>" style="width:300px;"></td>
<td><%=User.where({:id=>a_picture.owner_id}).at(0).username%></td>
<td><%=a_picture.caption%></td>
<td><%=a_picture.created_at%></td>
<td><a href="/photos/<%=a_picture.id%>">Show detail</a></td>
</tr>
<%end%>
</table>
45 changes: 45 additions & 0 deletions app/views/photo_templates/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<h1>Show Details</h1>
<dl>
<dt>Image</dt>
<dd><img src="<%= @the_photo.image%>" style="width:300px;"></dd>

<dt>Caption</dt>
<dd><%=@the_photo.caption%></dd>

<dt>Owner</dt>
<dd><%=@the_photo.poster.username%></dd>

<dt>Posted</dt>
<dd><%=@the_photo.created_at%></dd>

<dt>Edit photo</dt>
<dd>
<form action="/edit_photo/<%=@the_photo.id%>">
<label for="url_box">Name</label>
<input type="text" id="url_box" name="url" value=<%=@the_photo.image%>>

<label for="caption_box">Name</label>
<input type="text" id="caption_box" name="caption" value=<%=@the_photo.caption%>>

<button>Update photo</button>
</dd>

<dt>Delete Photo</dt>
<dd><a href="/delete_photo/<%=@the_photo.id%>">Delete this photo</a></dd>
</dl>

<h1>Comments</h1>

<table>
<tr>
<th>Commenter</th>
<th>Comment</th>
<th>Posted</th>
</tr>
<%comments=@the_photo.comments%>
<%comments.each do |a_comment|%>
<tr>
<
</tr>

</table>
25 changes: 25 additions & 0 deletions app/views/user_templates/list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h1>List of users</h1>
<form action "/add_user" method="post">

<label for "user_box">Username</label>
<input type = "text" id = "user_box" name ="username" placeholder="Enter a username...">

<button>Add user</button>
</form>
<hr>

<table border="1">
<tr>
<th>ID</th>
<th>Username</th>
<th></th>
<% @user_list.each do |a_user| %>
<tr>
<td><%=a_user.id%></td>
<td><%=a_user.username%></td>
<td>
<a href="/users/<%=a_user.username%>">Show details</a>
</td>
</tr>
<%end%>
</table>
33 changes: 33 additions & 0 deletions app/views/user_templates/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h1><%=@the_user.username%></h1>

<dt>ID</dt>
<dd><%=@the_user.id%></dd>

<dt>Edit user<dt>
<dd>
<form action= "/edit_user/<%=@the_user.username%>" method="post">
<label for "username_box">Username</label>
<input type="text" id="username_box" name="username" value=<%=@the_user.username%>>
<button>Update user</button>
</form>
</dd>
<h1>Own photos</h1>
<table border=1>
<tr>
<th>Image</th>
<th>Owner</th>
<th>Caption</th>
<th>Posted</th>
<th></th>
</tr>
<%pics=@the_user.own_photos%>
<%pics.each do |a_picture|%>
<tr>
<td><img src="<%= a_picture.image%>" style="width:300px;"></td>
<td><%=User.where({:id=>a_picture.owner_id}).at(0).username%></td>
<td><%=a_picture.caption%></td>
<td><%=a_picture.created_at%></td>
<td><a href="/photos/<%=a_picture.id%>">Show detail</a></td>
</tr>
<%end%>
</table>
9 changes: 9 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Rails.application.routes.draw do
get("/", { :controller => "misc", :action => "homepage" })

get("/users", { :controller => "users", :action => "list" })
get("/users/:path_id", { :controller => "users", :action => "show" })
post("/add_user", { :controller => "users", :action => "insert" })
post("/edit_user/:path_id",{:controller => "users",:action => "edit"})

get("/photos",{:controller => "photos",:action=>"list"})
get("/photos/:path_id", { :controller => "photos", :action => "show" })

end
Binary file added db/development.sqlite3
Binary file not shown.
Binary file added db/test.sqlite3
Binary file not shown.