【问题标题】:RefineryCms engine generation with resource type wrong generated生成资源类型错误的 RefineryCms 引擎生成
【发布时间】:2014-04-02 11:05:35
【问题描述】:

我是 RefineryCMS 和 Rails 的初学者。我制作了我的 RefineryCMS 应用程序,我正在尝试生成我的引擎,如指南中所述。 我正在运行这个命令:

rails g refinery:engine article title:string reference:string file:resource

在我进入管理部分的视图中,没有用于浏览的按钮或文件资源的任何预期内容,只有一个用于介绍文本的框。这是部分表单的一部分:

  <div class='field'>
    <%= f.label :file_id -%>
    <%= f.text_field :file_id -%>
  </div>

RefineryCMS Engines Error: did not have a valid gemspec所述,我不得不更改引擎中的 gemspec 文件

这是我的 gemfile 的一部分:

ruby '2.1.1'
gem 'rails', '3.2.17'
gem 'pg'
# Refinery CMS
gem 'refinerycms', '~> 2.1.0'

# Optionally, specify additional Refinery CMS Extensions here:
gem 'refinerycms-acts-as-indexed', '~> 1.0.0'

# Refinery's news engine allows you to post updates to the news section of your website.
gem 'refinerycms-news', '~> 2.1.0'
gem 'refinerycms-articles', :path => 'vendor/extensions'

我使用的是 Ubuntu 13.10。

这是一个错误还是我做错了什么?如何获得浏览文件的按钮?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 refinerycms


    【解决方案1】:

    好的,我已经想出了如何解决这个问题,感谢另一个问题:https://english.stackexchange.com/questions/11481

    问题是生成器没有创建正确的视图和模型。您必须手动进行此修改。

    视图中的第一个_form.html.erb:

    <div class='field'>
        <%= f.label :file_id -%>
        <%= render :partial => "/refinery/admin/resource_picker", :locals =>
        {
              :f => f,
              :field => :file_id,
              :resource => @article.file} %>
    </div>
    

    现在将这一行添加到模型中,article.rb

    belongs_to :file, :class_name=>'Resource'
    

    当然,您也必须修改显示视图。例如:

      <section>
        <h1>File</h1>
        <p>
          <%= link_to("Download", @article.file.url) if @article.file %>
        </p>
      </section>
    

    如果生成器能自动完成这一切会很好,但这样你就可以让它工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 2015-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多