[英]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
Presumably something like this in your index.html.erb 在您的index.html.erb中大概是这样的
<% @microposts.each do |micropost| %>
<%= render partial: 'micropost', locals: { :micropost => micropost} %>
<% end %>
The partial name is just what the file is called minus the _ and .html.erb. 部分名称就是文件名减去_和.html.erb。 Locals passes the variables to the partial
当地人将变量传递给部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.