Complete Lesson 27
This commit is contained in:
parent
014c15fe4e
commit
09eda4f4e0
@ -1,2 +1,25 @@
|
||||
class UsersController < ApplicationController
|
||||
def index
|
||||
@users = User.all
|
||||
end
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
if @user.save
|
||||
redirect_to @user, notice: "Thanks for signing up!"
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
||||
end
|
||||
end
|
||||
|
@ -3,4 +3,10 @@
|
||||
<h1>The only movies that actually matter</h1>
|
||||
<%= link_to image_tag("logo.png"), root_path %>
|
||||
</div>
|
||||
<ul class="left">
|
||||
<li><%= link_to "All Movies", movies_path, class: "btn" %></li>
|
||||
</ul>
|
||||
<ul class="right">
|
||||
<li><%= link_to "Sign Up", signup_path, class: "button btn" %></li>
|
||||
</ul>
|
||||
</header>
|
||||
|
17
app/views/users/_form.html.erb
Normal file
17
app/views/users/_form.html.erb
Normal file
@ -0,0 +1,17 @@
|
||||
<%= form_with(model: user) do |f| %>
|
||||
<%= render "shared/errors", object: user %>
|
||||
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name, autofocus: true %>
|
||||
|
||||
<%= f.label :email %>
|
||||
<%= f.email_field :email %>
|
||||
|
||||
<%= f.label :password %>
|
||||
<%= f.password_field :password %>
|
||||
|
||||
<%= f.label :password_confirmation, "Confirm Password" %>
|
||||
<%= f.password_field :password_confirmation %>
|
||||
|
||||
<%= f.submit %>
|
||||
<% end %>
|
10
app/views/users/index.html.erb
Normal file
10
app/views/users/index.html.erb
Normal file
@ -0,0 +1,10 @@
|
||||
<h1><%= pluralize(@users.size, "User") %></h1>
|
||||
<ul class="users">
|
||||
<% @users.each do |user| %>
|
||||
<li>
|
||||
<%= link_to user.name, user %>
|
||||
created
|
||||
<%= time_ago_in_words(user.created_at) %> ago
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
3
app/views/users/new.html.erb
Normal file
3
app/views/users/new.html.erb
Normal file
@ -0,0 +1,3 @@
|
||||
<h1>Sign Up</h1>
|
||||
|
||||
<%= render "form", user: @user %>
|
4
app/views/users/show.html.erb
Normal file
4
app/views/users/show.html.erb
Normal file
@ -0,0 +1,4 @@
|
||||
<section class="user">
|
||||
<h1><%= @user.name %></h1>
|
||||
<h2><%= mail_to(@user.email) %></h2>
|
||||
</section>
|
@ -6,4 +6,6 @@ Rails.application.routes.draw do
|
||||
resources :movies do
|
||||
resources :reviews
|
||||
end
|
||||
|
||||
get "signup" => "users#new"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user