Submitted Lab3

parent 81711d48
......@@ -9,13 +9,14 @@ module Admin
def edit
@post = Post.find(params[:id])
@user = @post.user
end
def update
@post = Post.find(params[:id])
if @post.update(post_params())
redirect_to post_path(@post.id)
redirect_to admin_post_path(@post.id)
else
render "admin/posts/edit.html.erb"
end
......@@ -27,8 +28,9 @@ module Admin
end
def create
@post = Post.new(post_params())
@post = current_user.posts.new(post_params)
@user = current_user
@users = User.all
if @post.save
redirect_to post_path(@post.id)
else
......@@ -38,7 +40,8 @@ module Admin
def show
@post = Post.find(params[:id])
@user = post.user
@users = User.all
render "admin/posts/show.html.erb"
end
......
......@@ -7,6 +7,7 @@ class PostsController < ApplicationController
def edit
@post = Post.find(params[:id])
@user = @post.user
end
def update
......@@ -25,7 +26,9 @@ class PostsController < ApplicationController
end
def create
@post = Post.new(post_params())
@post = current_user.posts.new(post_params)
@user = current_user
@users = User.all
if @post.save
redirect_to post_path(@post.id)
......@@ -36,7 +39,8 @@ class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
@user = @post.user
@users = User.all
render "posts/show.html.erb"
end
......
class UserControll < ApplicationController
def posts
@user = User.find(params[:id])
@posts = @user
end
end
\ No newline at end of file
<%= simple_form_for([:admin, @post]) do |f| %>
<%= f.input :title %>
<%= f.association :category %>
<%= f.association :category, as: :select, collection: ["a", "b", "c"] %>
<%= f.input :published_at %>
<%= f.input :content %>
<%= f.input :is_published %>
......
......@@ -7,13 +7,15 @@
<table width="100%">
<tr>
<th>Title</th>
<th>Published by </th>
<th>Published At</th>
<th>Pusblished?</th>
<th>Published?</th>
<th>Actions</th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.user.email %> </td>
<td><%= post.published_at %></td>
<td><%= post.is_published %></td>
<td>
......@@ -24,3 +26,5 @@
</tr>
<% end %>
</table>
<hr>
<%= link_to "Home", root_path %>
<h1><%= @post.title %></h1>
<h3><%= @post.published_at %></h3>
<h4>by <%= current_user.email %> </h4>
<h4>by <%= user.email %> </h4>
<p>
<%= @post.content %>
......
<h2>Resend confirmation instructions</h2>
<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :confirmation_token %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
<p>Hello <%= @resource.email %>!</p>
<p>We're contacting you to notify you that your password has been changed.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
<h2>Change your password</h2>
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<%= f.input :reset_password_token, as: :hidden %>
<%= f.full_error :reset_password_token %>
<div class="form-inputs">
<%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, label: "Confirm your new password", required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Change my password" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<h2>Forgot your password?</h2>
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Send me reset password instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %>
<%= f.input :password_confirmation, required: false %>
<%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>
<h2>Sign up</h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Sign up" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<h2>Log in</h2>
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email, required: false, autofocus: true %>
<%= f.input :password, required: false %>
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
</div>
<div class="form-actions">
<%= f.button :submit, "Log in" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
<h2>Resend unlock instructions</h2>
<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= f.error_notification %>
<%= f.full_error :unlock_token %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
</div>
<div class="form-actions">
<%= f.button :submit, "Resend unlock instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
......@@ -15,13 +15,15 @@
<% end %>
<hr>
<% @categories.each do |c| %>
<% @categories.each do |c| %>
<h2>(<%= c.id %>) <%= c.name %></h2>
<ul>
<% c.posts.each do |p| %>
<li><%= link_to p.title, post_path(p.id) %></li>
<% end %>
</ul>
<%= link_to "View all Posts", "/categories/#{c.id}" %>
<% end %>
<ul>
<% c.posts.each do |p| %>
<li><%= link_to p.title, post_path(p.id) %></li>
<% end %>
</ul>
<%= link_to "View all Posts", "/categories/#{c.id}" %>
<% end %>
......@@ -5,19 +5,25 @@
<%= link_to"Log out", destroy_user_session_path, :method => :delete %>
<hr>
<%= link_to "Edit Posts", admin_posts_path %>
<hr>
<table width="100%">
<tr>
<th>Title</th>
<th>Category</th>
<th>Published by</th>
<th>Published At</th>
<th>Pusblished?</th>
<th>Published?</th>
<th>Actions</th>
</tr>
<% @posts.each do |post| %>
<hr>
<tr>
<td><%= post.title %></td>
<td><%= post.category.name %></td>
<td><%= post.user.email %></td>
<td><%= post.published_at %></td>
<td><%= post.is_published %></td>
......@@ -25,6 +31,7 @@
<%= link_to "Show", post_path(post.id) %>
</td>
</tr>
<% end %>
</table>
<% else %>
......
......@@ -3,6 +3,7 @@
<% if user_signed_in? %>
<h1><%= @post.title %></h1>
<h2>Published by:<%= @user.email %></h2>
<h3><%= @post.published_at %></h3><p>
<%= @post.content %>
</p>
......
<% @posts.each do |post| %>
<%= post.inspect %>
<% end %>
\ No newline at end of file
......@@ -3,7 +3,7 @@ Rails.application.routes.draw do
root to: "pages#index"
resources :posts
get "/categories/:id", to: "categories#show"
get 'users/:id/posts' => 'users#posts', :as => :user_posts
namespace :admin do
resources :posts
......
class AddUserId < ActiveRecord::Migration
def change
add_column :posts, :user_id, :integer
end
end
class AddUserId < ActiveRecord::Migration
def change
add_column :posts, :user_id, :integer
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160716072931) do
ActiveRecord::Schema.define(version: 20160717025302) do
create_table "categories", force: :cascade do |t|
t.string "name"
......@@ -27,6 +27,7 @@ ActiveRecord::Schema.define(version: 20160716072931) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "category_id"
t.integer "user_id"
end
create_table "users", force: :cascade do |t|
......
This diff is collapsed.
I"/C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/javascripts/application.js?type=application/javascript&id=5fc51d5d88e847935bf736ae2db1db42cf52bd8b8679105e131f50e52f7026db:ET
\ No newline at end of file
[o:Set:
@hash{ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"0processors:type=text/css&file_type=text/css;TTI"}file-digest:///C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets/application.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"mfile-digest:///C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets;TT
\ No newline at end of file
I"/C:/Bitnami/rubystack-2.2.5-3/ruby/lib/ruby/gems/2.2.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts/jquery.js?type=application/javascript&pipeline=self&id=a5c87903a2374d47dd729f064533f76fef2a4a680ed13f94a18b796345e77b18:ET
\ No newline at end of file
I"/C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/javascripts/application.js?type=application/javascript&pipeline=debug&id=2c4500260a7811785e765aa4582f3155205c228f2f183aa5d4a0107cf49fb455:ET
\ No newline at end of file
I"/C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets/application.css?type=text/css&pipeline=debug&id=44da1a88abb05b0541938ffb3cd5c2888d2633d903b2d3c8c8468ac2e1c7e042:ET
\ No newline at end of file
I"/C:/Bitnami/rubystack-2.2.5-3/ruby/lib/ruby/gems/2.2.0/gems/turbolinks-source-5.0.0/lib/assets/javascripts/turbolinks.js?type=application/javascript&pipeline=self&id=f9eef14140bc22e5b13af7388874f3d501b9e37816a54fdf2725bf28c03d6e32:ET
\ No newline at end of file
[o:Set:
@hash{
I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"file-digest:///C:/Bitnami/rubystack-2.2.5-3/ruby/lib/ruby/gems/2.2.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts/jquery_ujs.js;TT
\ No newline at end of file
I"/C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets/application.css?type=text/css&pipeline=self&id=65413b5d48485963a1f1f7e428d10c2bbd1960aa72001e6e0ea2c78433925dd8:ET
\ No newline at end of file
I"/C:/Bitnami/rubystack-2.2.5-3/ruby/lib/ruby/gems/2.2.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts/jquery_ujs.js?type=application/javascript&pipeline=self&id=53a67bbc04c64d05c8215ebc9312e7605bb07f18e135edf19cb7b0a80fe82425:ET
\ No newline at end of file
[o:Set:
@hash{
I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"file-digest:///C:/Bitnami/rubystack-2.2.5-3/ruby/lib/ruby/gems/2.2.0/gems/turbolinks-source-5.0.0/lib/assets/javascripts/turbolinks.js;TT
\ No newline at end of file
[o:Set:
@hash{ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"?processors:type=text/css&file_type=text/css&pipeline=debug;TTI"}file-digest:///C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets/application.css;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"mfile-digest:///C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets;TT
\ No newline at end of file
I"/C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/javascripts/application.js?type=application/javascript&pipeline=self&id=9f452fc9a868b0fd7e1537ef06f5e15589e210d2a29691fafdd7f9a35a42dc88:ET
\ No newline at end of file
I"/C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets/application.css?type=text/css&id=18d514a8ed8e12823e6ea7a1385ee2e97ed1afa17e8118c37887017c5b299a46:ET
\ No newline at end of file
[o:Set:
@hash{ I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI">processors:type=text/css&file_type=text/css&pipeline=self;TTI"}file-digest:///C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets/application.css;TTI"mfile-digest:///C:/Users/Koki%20Mamards/Desktop/submissions/144666/blog%20gonzales/app/assets/stylesheets;TT
\ No newline at end of file
[o:Set:
@hash{
I"environment-version:ETTI"environment-paths;TTI"rails-env;TTI"Zprocessors:type=application/javascript&file_type=application/javascript&pipeline=self;TTI"file-digest:///C:/Bitnami/rubystack-2.2.5-3/ruby/lib/ruby/gems/2.2.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts/jquery.js;TT
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment