[英]Why doesnt my html show up in my ruby on rails application
So I am trying to add replies to the microposts found in this application https://github.com/railstutorial/sample_app_2nd_ed 因此,我正在尝试对在此应用程序中找到的微博添加回复https://github.com/railstutorial/sample_app_2nd_ed
I think I figured out all of the model and controller stuff but that is besides the point. 我想我已经弄清楚了所有模型和控制器的内容,但是那不是重点。
When I try to add a reply link to app/views/microposts/_micropost.html.erb. 当我尝试向app / views / microposts / _micropost.html.erb添加回复链接时。 it never works.
它永远都行不通。
<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>
as you can see I have tried on lines 3 13 and 15 to add a basic text or a reply link. 如您所见,我已经尝试在3 13和15行添加基本文本或回复链接。 It never shows up.
它永远不会出现。 am I doing this wrong?
我做错了吗? What format should I put a reply link/even basic text I want to show up in?
我应该以哪种格式显示回复链接/甚至要显示的基本文字?
Here is my micropost controller code 这是我的micropost控制器代码
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
and here is my comments controller 这是我的评论控制器
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
Also as requested, here is the show.html.erb file which renders the micropost partial 同样根据要求,这里是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>
Can you post your controller code? 您可以发布您的控制器代码吗? Usually, you set member variables in controllers so your erb looks like this:
通常,您在控制器中设置成员变量,因此erb如下所示:
<%= @micropost.content %>
And your controller like this: 和您的控制器是这样的:
def show
@micropost = Micropost.find(params[:id])
end
In show.html.erb, you have to add the following line to render your 'micropost' partial in show view. 在show.html.erb中,您必须添加以下行以在“显示”视图中部分渲染“ micropost”。
<%= render 'micropost' %> <%=渲染'micropost'%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.