为什么我的html不会出现在我的ruby on rails应用程序中?

时间:2012-05-11 00:50:14

标签: ruby-on-rails

所以我正在尝试添加对此应用程序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

1 个答案:

答案 0 :(得分:0)

你的index.html.erb

中可能是这样的
<% @microposts.each do |micropost| %>
  <%= render partial: 'micropost', locals: { :micropost => micropost} %>
<% end %>

部分名称就是文件的名称减去_和.html.erb。当地人将变量传递给部分