Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class UsersController < ApplicationController | ||
def index | ||
@users = User.all | ||
end | ||
|
||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
@user = User.new(params.require(:user).permit(:name, :email)) | ||
|
||
if @user.save | ||
redirect_to @user, notice: 'You have successfully created a user!' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def show | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
def destroy | ||
@user = User.find(params[:id]) | ||
@user.destroy | ||
|
||
redirect_to users_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class User < ActiveRecord::Base | ||
validates_presence_of :name, :email | ||
validates_format_of :email, with: /@/ | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div> | ||
<%= link_to 'New User', new_user_path %> | ||
</div> | ||
|
||
<% @users.each do |user| %> | ||
<div> | ||
<div><%= link_to user.name, user %></div> | ||
<div><%= user.email %></div> | ||
<div><%= link_to 'Delete', user, method: :delete %></div> | ||
</div> | ||
<hr/> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<%= form_for @user do |f| %> | ||
<% if @user.errors.any? %> | ||
<div> | ||
<ul> | ||
<% @user.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
</div> | ||
<div> | ||
<%= f.label :email %> | ||
<%= f.text_field :email %> | ||
</div> | ||
<div> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div> | ||
<div><%= link_to @user.name, @user %></div> | ||
<div><%= @user.email %></div> | ||
<div><%= link_to 'Delete', @user, method: :delete %></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateUsers < ActiveRecord::Migration | ||
def change | ||
create_table :users do |t| | ||
t.string :name | ||
t.string :email | ||
|
||
t.timestamps null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters