简体   繁体   English

为什么我的HTML不显示在我的ruby on rails应用程序中

[英]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.

相关问题 为什么我的html不显示在我的ruby on rails应用程序中? - Why doesnt my html show up in my ruby on rails application? 我的表单未显示在视图中-Ruby on Rails? - My form does not show up in the view -Ruby on Rails? Ruby on Rails:localhost:3000 / my_pages_dont_show_up - Ruby on Rails: localhost:3000/my_pages_dont_show_up 测试我的Ruby on Rails应用程序 - Testing my Ruby on Rails application 为什么我的ruby on rails应用程序无法在我的部分html页面中呈现Rails代码? - Why is my ruby on rails app not rendering rails code in my partial html page? 将Ruby应用程序与我的Rails应用程序集成 - Integrate Ruby application with my Rails application 为什么我的rails页面总是显示html头? - why my rails page always show html heads? 当我在Ruby on rails应用程序中将数据转储到我的MySQL表中时,为什么它会显示特殊字符? - When i dump data in my MySQL tables in my Ruby on rails application, why it displays special characters? 为什么我的HTML模板在Ruby on Rails的控制器中不显示图像/外部CSS的定义? - Why won't my HTML template display images/external css for definitions in my controller in Ruby on Rails? 在rails应用程序中将引导程序流水线化到我的ruby中以对其进行样式化 - Pipelining bootstrap into my ruby on rails application to style it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM