【问题标题】:Rails can't find my partial. Missing partial errorRails 找不到我的部分。缺少部分错误
【发布时间】:2014-03-29 18:25:08
【问题描述】:

我生成了一个名为 Comment 的新模型。

rails g model Comment user_id:integer content:text
rake db:migrate

然后我创建一个简单的局部视图,我打算从另一个控制器/视图调用它。

产品展示视图内部:

.comments
  h3
    | Questions and Answers:
    small for #{@product.name}

    = render 'comments/new'

缺少带有 {:locale=>[:en]、:formats=>[:html] 的部分 cmets/new, :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim, :coffee]}。 搜索:* "/Users/sergiotapia/Documents/Work/foobar/app/views"

我停止并启动了 Rails 应用程序,但它仍然拒绝检测部分。我忽略了什么吗?

我不希望将评论表单移至 Products 文件夹。

【问题讨论】:

    标签: ruby-on-rails view partial


    【解决方案1】:

    文件扩展名不正确

    将部分文件重命名为_new.html.slim。目前html 拼写错误hmtl

    【讨论】:

    • sigh - 是时候喝杯咖啡了。
    • 绝对需要一杯咖啡。享受!! :)
    【解决方案2】:

    试试这个:

    2.2.4 渲染任意文件

    render 方法也可以使用完全在你的视图之外的视图 应用程序(也许你在两个 Rails 之间共享视图 应用程序):

    render "/u/apps/warehouse_app/current/app/views/products/show"
    

    Rails 确定这是一个文件渲染,因为前导 斜线字符。明确地说,您可以使用 :file 选项(其中 Rails 2.2 及更早版本需要):

    render file:"/u/apps/warehouse_app/current/app/views/products/show"
    

    :file 选项采用绝对文件系统路径。当然,你 需要对您用来呈现视图的视图拥有权限 内容。

    取自这里:http://guides.rubyonrails.org/layouts_and_rendering.html

    编辑: 哦,当然,文件名不正确,没看到。 ;) 见 Kirti Thorat 的回答。

    【讨论】:

    • 显然问题在于命名部分文件。请参阅 kirti Thorat 的回答。
    猜你喜欢
    • 1970-01-01
    • 2021-10-24
    • 2016-02-25
    • 1970-01-01
    • 2017-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多