Skip to content

Commit

Permalink
edited users and listed articles on profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitchauhan2065 committed Apr 10, 2018
1 parent eab1cdd commit 405d562
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 90 deletions.
31 changes: 31 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,37 @@ def create
end
end

def edit

@user = User.find(params[:id])

end

def update

@user = User.find(params[:id])

if @user.update(user_params)

flash[:success] = "Your account was updated successfully"

redirect_to articles_path

else

render 'edit'

end

end

def show

@user = User.find(params[:id])

end


private

def user_params
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
module ApplicationHelper

def gravatar_for(user, options = { size: 80})

gravatar_id = Digest::MD5::hexdigest(user.email.downcase)

size = options[:size]

gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"

image_tag(gravatar_url, alt: user.username, class: "img-circle")

end
end
47 changes: 47 additions & 0 deletions app/views/articles/_article.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<% obj.each do |article| %>

<div class="row">

<div class="col-xs-8 col-xs-offset-2">

<div class="well well-lg">

<div class="article-title">

<%= link_to article.title, article_path(article) %>

</div>

<div class="article-body">

<%= truncate(article.description, length: 100) %>
<div class="article-meta-details">


<small> Created by: <%= article.user.username if article.user %>,
<%= time_ago_in_words(article.created_at) %> ago,
last updated: <%= time_ago_in_words(article.updated_at) %> ago
</small>

</div>
</div>

<div class="article-actions">

<%= link_to "Edit this article", edit_article_path(article), class: "btn btn-xs btn-primary" %>
<%= link_to "Delete this article", article_path(article), method: :delete,

data: { confirm: "Are you sure you want to delete the article?"},

class: "btn btn-xs btn-danger" %>

</div>

</div>

</div>

</div>

<% end %>
48 changes: 1 addition & 47 deletions app/views/articles/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
<h1 align="center">Listing all articles</h1>

<% @articles.each do |article| %>

<div class="row">

<div class="col-xs-8 col-xs-offset-2">

<div class="well well-lg">

<div class="article-title">

<%= link_to article.title, article_path(article) %>

</div>

<div class="article-body">

<%= truncate(article.description, length: 100) %>
<div class="article-meta-details">


<small> Created by: <%= article.user.username if article.user %>,
<%= time_ago_in_words(article.created_at) %> ago,
last updated: <%= time_ago_in_words(article.updated_at) %> ago
</small>

</div>
</div>

<div class="article-actions">

<%= link_to "Edit this article", edit_article_path(article), class: "btn btn-xs btn-primary" %>
<%= link_to "Delete this article", article_path(article), method: :delete,

data: { confirm: "Are you sure you want to delete the article?"},

class: "btn btn-xs btn-danger" %>

</div>

</div>

</div>

</div>

<% end %>
<%= render 'article', obj: @articles %>
43 changes: 43 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%= render "shared/errors", obj: @user %>

<div class="row">
<div class="col-xs-12">

<%= form_for(@user, :html => {class: "form-horizontal", row: "form"}) do |f| %>
<div class="form-group">
<div class="control-label col-sm-2">
<%= f.label :username %>
</div>
<div class="col-sm-8">
<%= f.text_field :username, class: "form-control", placeholder: "Enter username", autofocus: true %>
</div>
</div>

<div class="form-group">
<div class="control-label col-sm-2">
<%= f.label :email %>
</div>
<div class="col-sm-8">
<%= f.email_field :email, class: "form-control", placeholder: "Enter email" %>
</div>
</div>
<div class="form-group">
<div class="control-label col-sm-2">
<%= f.label :password %>
</div>
<div class="col-sm-8">
<%= f.password_field :password, class: "form-control", placeholder: "Enter password" %>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<%= f.submit 'Sign up', class: "btn btn-primary btn-lg" %>
</div>
</div>
<% end %>

<div class="col-xs-4 col-xs-offset-4">
[ <%= link_to "Cancel request and return to articles listing", articles_path %> ]
</div>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1 align="center">Edit your account</h1>

<%= render 'form' %>
44 changes: 1 addition & 43 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,4 @@
Signup for alpha blog
</h1>

<%= render "shared/errors", obj: @user %>

<div class="row">
<div class="col-xs-12">

<%= form_for(@user, :html => {class: "form-horizontal", row: "form"}) do |f| %>
<div class="form-group">
<div class="control-label col-sm-2">
<%= f.label :username %>
</div>
<div class="col-sm-8">
<%= f.text_field :username, class: "form-control", placeholder: "Enter username", autofocus: true %>
</div>
</div>

<div class="form-group">
<div class="control-label col-sm-2">
<%= f.label :email %>
</div>
<div class="col-sm-8">
<%= f.email_field :email, class: "form-control", placeholder: "Enter email" %>
</div>
</div>
<div class="form-group">
<div class="control-label col-sm-2">
<%= f.label :password %>
</div>
<div class="col-sm-8">
<%= f.password_field :password, class: "form-control", placeholder: "Enter password" %>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<%= f.submit 'Sign up', class: "btn btn-primary btn-lg" %>
</div>
</div>
<% end %>

<div class="col-xs-4 col-xs-offset-4">
[ <%= link_to "Cancel request and return to articles listing", articles_path %> ]
</div>
</div>
</div>
<%= render 'form' %>
15 changes: 15 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1 align="center">Welcome to <%= @user.username %>'s page</h1>

<div class="row">

<div class="col-md-4 col-md-offset-4 center">

<%= gravatar_for @user, size: 150 %>

</div>

</div>

<h4 align="center"><%= @user.username %>'s articles</h4>

<%= render 'articles/article', obj: @user.articles %>

0 comments on commit 405d562

Please sign in to comment.