Complete Lesson 27

main
Simon Quigley 1 year ago
parent 014c15fe4e
commit 09eda4f4e0

@ -1,2 +1,25 @@
class UsersController < ApplicationController 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 end

@ -3,4 +3,10 @@
<h1>The only movies that actually matter</h1> <h1>The only movies that actually matter</h1>
<%= link_to image_tag("logo.png"), root_path %> <%= link_to image_tag("logo.png"), root_path %>
</div> </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> </header>

@ -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 %>

@ -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>

@ -0,0 +1,3 @@
<h1>Sign Up</h1>
<%= render "form", user: @user %>

@ -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 :movies do
resources :reviews resources :reviews
end end
get "signup" => "users#new"
end end

Loading…
Cancel
Save