2014-04-02 35 views
1

我是RefineryCMS和Rails的初学者。我制作了我的RefineryCMS应用程序,并试图生成我的引擎,如指南中所述。 我运行此命令: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> 

我不得不改变gemspec文件中发动机所提到RefineryCMS Engines Error: did not have a valid 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。

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

回答

2

好吧,我想通了,如何解决这个问题,感谢这个其他quetion: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' 

当然,你必须也修改show view。例如:

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

如果发生器会自动完成这一切,但是这样你就可以使用它,这样会很好。