所以我试图添加对此应用程序中发现的微博的回复 https://github.com/railstutorial/sample_app_2nd_ed
我想我找出了所有的模型和控制器的东西,但这是重点。
当我尝试向app / views / microposts / _micropost.html.erb添加回复链接时。它永远不会奏效。
<li>
<span class="content"><%= micropost.content %></span>
<p>this text doesnt show up!</p>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
<% if current_user?(micropost.user) %>
<%= link_to "delete", micropost, method: :delete,
confirm: "You sure?",
title: micropost.content %>
<% end %>
<%= link_to "reply", new_comment_path(:micropost_id => comment) %> |
<p> why isnt this working!!?</p>
</li>
如您所见,我已尝试在第3 13和15行添加基本文本或回复链接。它永远不会出现。我做错了吗?我应该以什么格式提供回复链接/甚至我想要显示的基本文字?
这是我的微博控制器代码
class MicropostsController < ApplicationController
before_filter :signed_in_user
before_filter :correct_user, only: :destroy
def create
@micropost = current_user.microposts.build(params[:micropost])
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to root_path
else
@feed_items = []
render 'static_pages/home'
end
end
def destroy
@micropost.destroy
redirect_back_or root_path
end
private
def correct_user
@micropost = current_user.microposts.find_by_id(params[:id])
redirect_to root_path if @micropost.nil?
end
end
这是我的评论控制器
class CommentsController < ApplicationController
def create
@comment = @micropost.comments.new(params[:comment])
if @comment.save
redirect_to @user
else
redirect_to @user
end
end
def destroy
@comment.destroy
redirect_back_or root_path
end
end
同样根据要求,这里是show.html.erb文件,它呈现微博部分
<% provide(:title, @user.name) %>
<div class="row">
<aside class="span4">
<section>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
</section>
</aside>
<div class="span8">
<%= render 'follow_form' if signed_in? %>
<% if @user.microposts.any? %>
<h3>Microposts (<%= @user.microposts.count %>)</h3>
<ol class="microposts">
<%= render @microposts %>
</ol>
<%= will_paginate @microposts %>
<% end %>
</div>
</div>
答案 0 :(得分:0)
您可以发布您的控制器代码吗? 通常,您在控制器中设置成员变量,因此您的erb如下所示:
<%= @micropost.content %>
你的控制器是这样的:
def show
@micropost = Micropost.find(params[:id])
end
答案 1 :(得分:0)
在show.html.erb中,您必须添加以下行以在展示视图中呈现“微博”部分。
&lt;%=渲染'微博'%&gt;