Skip to content

Instantly share code, notes, and snippets.

@vjm
Created June 30, 2011 13:08
Show Gist options
  • Select an option

  • Save vjm/1056194 to your computer and use it in GitHub Desktop.

Select an option

Save vjm/1056194 to your computer and use it in GitHub Desktop.

Revisions

  1. vjm revised this gist Jun 30, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html.erb
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@
    <th><%= user.created_at.to_s(:datetime).downcase %></th>
    <th><%= user.updated_at.to_s(:datetime).downcase %></th>
    <th><%= link_to "Edit", edit_user_path(user) %></th>
    <th><%= link_to "Delete", users_path, :method => :delete, :confirm => "Are you sure?" %></th>
    <th><%= link_to "Delete", user, :method => :delete, :confirm => "Are you sure?" %></th>
    </tr>
    <% end %>
    </tbody>
  2. @invalid-email-address Anonymous renamed this gist Jun 30, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @invalid-email-address Anonymous created this gist Jun 30, 2011.
    42 changes: 42 additions & 0 deletions _form.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    <%= form_for(@user) do |f| %>
    <% if @user.errors.any? %>
    <div id="error_explanation">
    <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

    <ul>
    <% @user.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
    <% end %>
    </ul>
    </div>
    <% end %>

    <p><%= f.label :username %><br />
    <%= f.text_field :username %></p>

    <p><%= f.label :first_name %><br />
    <%= f.text_field :first_name %></p>

    <p><%= f.label :last_name %><br />
    <%= f.text_field :last_name %></p>

    <p><%= f.label :email %><br />
    <%= f.email_field :email %></p>

    <% if action_name == "new" %>
    <p><%= f.label :password, "New password" %><br />
    <%= f.password_field :password %></p>

    <p><%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation %></p>
    <% end %>

    <p>
    <%= f.label :role %><br />
    <%= f.collection_select :role, User::ROLES, :to_s, :humanize %>
    </p>

    <div class="actions">
    <%= f.submit %>
    </div>
    <% end %>
    23 changes: 23 additions & 0 deletions _passwords.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <%= form_for(@user) do |f| %>
    <% if @user.errors.any? %>
    <div id="error_explanation">
    <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

    <ul>
    <% @user.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
    <% end %>
    </ul>
    </div>
    <% end %>

    <p><%= f.label :password, "New password" %><br />
    <%= f.password_field :password %></p>

    <p><%= f.label :password_confirmation %><br />
    <%= f.password_field :password_confirmation %></p>

    <div class="actions">
    <%= f.submit "Change password" %>
    </div>
    <% end %>
    7 changes: 7 additions & 0 deletions edit.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <h2>Edit user</h2>

    <%= render 'form' %>
    <p></p>
    <%= render 'passwords' %>

    <%= link_to 'All users', users_path %>
    40 changes: 40 additions & 0 deletions index.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <h1>All Users</h1>

    <table id="users">
    <thead>
    <tr>
    <th>Username</th>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Email</th>
    <th>Login Count</th>
    <th>Last Sign In</th>
    <th>Role</th>
    <th>Created At</th>
    <th>Last Edited</th>
    <th></th>
    <th></th>
    </tr>
    </thead>
    <tbody>
    <% @users.each do |user| %>
    <tr>
    <th><%= user.username %></th>
    <th><%= user.first_name %></th>
    <th><%= user.last_name %></th>
    <th><%= user.email %></th>
    <th><%= user.sign_in_count %></th>
    <th><%if user.last_sign_in_at.blank? %>Never logged in<% else %><%= time_ago_in_words(user.last_sign_in_at.to_datetime)+' ago' %><% end %></th>
    <th><%= user.role %></th>
    <th><%= user.created_at.to_s(:datetime).downcase %></th>
    <th><%= user.updated_at.to_s(:datetime).downcase %></th>
    <th><%= link_to "Edit", edit_user_path(user) %></th>
    <th><%= link_to "Delete", users_path, :method => :delete, :confirm => "Are you sure?" %></th>
    </tr>
    <% end %>
    </tbody>


    </table>

    <p><%= link_to "New User", new_user_path %></p>
    5 changes: 5 additions & 0 deletions new.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    <h2>Sign up</h2>

    <%= render 'form' %>

    <%= link_to 'All users', users_path %>
    4 changes: 4 additions & 0 deletions show.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    <p><%= @user.username %></p>
    <p><%= @user.first_name %></p>
    <p><%= @user.last_name %></p>
    <p><%= @user.email %></p>
    84 changes: 84 additions & 0 deletions users_controller.html.web
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    class UsersController < ApplicationController
    # GET /users
    # GET /users.json
    def index
    @users = User.all

    respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @users }
    end
    end


    # GET /users/1
    # GET /users/1.json
    def show
    @user = User.find(params[:id])

    respond_to do |format|
    format.html # show.html.erb
    format.json { render :json => @user }
    end
    end

    # GET /users/new
    # GET /users/new.json
    def new
    @user = User.new

    respond_to do |format|
    format.html # new.html.erb
    format.json { render :json => @user }
    end
    end

    # GET /users/1/edit
    def edit
    @user = User.find(params[:id])
    end

    # POST /users
    # POST /users.json
    def create
    @user = User.new(params[:user])

    respond_to do |format|
    if @user.save
    format.html { redirect_to @user, :notice => 'User was successfully created.' }
    format.json { render :json => @user, :status => :created, :location => @user }
    else
    format.html { render :action => "new" }
    format.json { render :json => @user.errors, :status => :unprocessable_entity }
    end
    end
    end

    # PUT /users/1
    # PUT /users/1.json
    def update
    @user = User.find(params[:id])

    respond_to do |format|
    if @user.update_attributes(params[:user])
    format.html { redirect_to @user, :notice => 'User was successfully updated.' }
    format.json { head :ok }
    else
    format.html { render :action => "edit" }
    format.json { render :json => @user.errors, :status => :unprocessable_entity }
    end
    end
    end

    # DELETE /users/1
    # DELETE /users/1.json
    def destroy
    @user = User.find(params[:id])
    @user.destroy

    respond_to do |format|
    format.html { redirect_to users_url }
    format.json { head :ok }
    end
    end
    end