Last active
December 14, 2015 11:29
-
-
Save alan707/5079909 to your computer and use it in GitHub Desktop.
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
<h1>Listing users</h1> | |
<table> | |
<tr> | |
<th>Firstname</th> | |
<th>Lastname</th> | |
<th>Email</th> | |
<th>Facebook ID</th> | |
<th>Facebook Username</th> | |
<th>Username</th> | |
<th></th> | |
<th></th> | |
<th></th> | |
</tr> | |
<% @users.each do |user| %> | |
<tr> | |
<td><%= user.try(:firstname) %></td> | |
<td><%= user.try(:lastname) %></td> | |
<td><%= user.try(:email) %></td> | |
<td><%= user.try(:facebook_id) %></td> | |
<td><%= user.try(:facebook_username) %></td> | |
<td><%= user.try(:username) %></td> | |
<td><%= link_to 'Show', user %></td> | |
<td><%= link_to 'Edit', edit_user_path(user) %></td> | |
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
</tr> | |
<% end %> | |
</table> | |
<br /> | |
<%= link_to 'New User', new_user_path %> |
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
users GET /users(.:format) users#index | |
POST /users(.:format) users#create | |
new_user GET /users/new(.:format) users#new | |
edit_user GET /users/:id/edit(.:format) users#edit | |
user GET /users/:id(.:format) users#show | |
PUT /users/:id(.:format) users#update | |
DELETE /users/:id(.:format) users#destroy | |
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
Started GET "/users" for 71.205.143.222 at 2013-03-04 03:54:09 +0000 | |
2013-03-04T03:54:09+00:00 app[web.1]: Processing by UsersController#index as HTML | |
2013-03-04T03:54:09+00:00 app[web.1]: Rendered users/index.html.erb within layouts/application (6.5ms) | |
2013-03-04T03:54:09+00:00 app[web.1]: Completed 500 Internal Server Error in 20ms | |
2013-03-04T03:54:09+00:00 app[web.1]: ActionController::RoutingError (No route matches {:action=>"show", :controller=>"users", :id=>#<User id: 15, firstname: "Jennifer", lastname: "Chaiwitz", email: nil, username: nil, created_at: "2013-03-03 01:15:45", updated_at: "2013-03-03 01:15:45", facebook_username: nil, photo_url: nil, facebook_id: 100005394060476>}): | |
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
class User < ActiveRecord::Base | |
attr_accessible :email, :facebook_id, :firstname, :lastname, :username, :facebook_username, :photo_url | |
def to_param | |
username | |
end | |
def as_json(options={}) | |
{:id => self.id, | |
:email => self.email, | |
:facebook_id => self.try(:facebook_id), | |
:firstname => self.firstname, | |
:lastname => self.lastname, | |
:username => self.username, | |
:facebook_username => self.try(:facebook_username), | |
:photo_url => self.try(:photo_url) | |
} | |
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment