在您的每个帖子中,也称为“胜利”,您可以将其公开或私有。如果它是私有的,它只会显示在您的个人资料中,而不会显示在常规Feed上。我已经显示了我的配置文件控制器,用于提交帖子的表单,即模式和配置文件显示视图。
配置文件控制器
class ProfilesController < ApplicationController
def show
# grab the username from the URL as :id
if (User.find_by_username(params[:id]))
@username = params[:id]
else
# redirect to 404 (root for now)
redirect_to root_path, :notice=> "User not found!"
end
@wins = Win.all.where("user_id = ?", User.find_by_username(params[:id]).id)
end
end
模式
create_table "wins", force: :cascade do |t|
t.string "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.integer "user_id"
t.boolean "display"
end
add_index "wins", ["user_id"], name: "index_wins_on_user_id"
end
显示个人资料
<%= render 'pages/home' unless user_signed_in? %>
<div id="wins" class="transitions-enabled">
<% @wins.each do |win| %>
<div class="box panel panel-default">
<%= link_to image_tag(win.image.url(:medium)), win %>
<div class="panel-body">
<p><%= win.description %></p>
<p><strong><%= win.user.name if win.user %></strong></p>
<p class="date"><%= win.created_at.strftime("%B %d, %Y") %></p>
<% if current_user && (win.user == current_user) %>
<div class="actions">
<%= link_to edit_win_path(win) do %>
<span class="glyphicon glyphicon-edit"></span> Edit
<% end %>
<%= link_to win, method: :delete, data: { confirm: 'Are you sure?' } do %>
<span class="glyphicon glyphicon-trash"></span> Delete
<% end %>
</div>
<% end %>
</div>
</div>
<% end %>
提交你的帖子又赢了
<%= form_for @win, html: { multipart: true } do |f| %>
<% if @win.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@win.errors.count, "error") %> prohibited this win from being saved:</h2>
<ul>
<% @win.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-group">
<%= f.label :image %>
<%= f.file_field :image, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :description %>
<%= f.text_field :description, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :display %>
<%= f.select(:display, options_for_select([['Public', 1], ['Private', 2]]), {}, { class:
"form-control"}) %>
</div>
<div class="form-group">
<%= f.submit class: "btn btn-danger" %>
</div>
<% end %>