diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3e74dea..5383b8e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index b67850f..75a8530 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -3,4 +3,10 @@

The only movies that actually matter

<%= link_to image_tag("logo.png"), root_path %> + + diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb new file mode 100644 index 0000000..3c9094a --- /dev/null +++ b/app/views/users/_form.html.erb @@ -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 %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 0000000..15e6fb6 --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,10 @@ +

<%= pluralize(@users.size, "User") %>

+ diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb new file mode 100644 index 0000000..ba9933f --- /dev/null +++ b/app/views/users/new.html.erb @@ -0,0 +1,3 @@ +

Sign Up

+ +<%= render "form", user: @user %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 0000000..10db66c --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,4 @@ +
+

<%= @user.name %>

+

<%= mail_to(@user.email) %>

+
diff --git a/config/routes.rb b/config/routes.rb index bd48338..265abb6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,4 +6,6 @@ Rails.application.routes.draw do resources :movies do resources :reviews end + + get "signup" => "users#new" end