Reputation: 366
I'm a beginner with RefineryCMS and Rails. I made my RefineryCMS app and I'm trying to generate my engine, as described in the guides. I'm running this command:
rails g refinery:engine article title:string reference:string file:resource
In the view I get in the Admin part there is no button to browse or anything as expected for the file resource, just a single box to introduce text. This is part of the form partial:
<div class='field'>
<%= f.label :file_id -%>
<%= f.text_field :file_id -%>
</div>
I had to change the gemspec file in the engine as mentioned RefineryCMS Engines Error: did not have a valid gemspec
this is part of my 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'
I'm using Ubuntu 13.10.
So is this a bug or I'm doing something wrong? How do I get a button to browse the file?
Upvotes: 1
Views: 327
Reputation: 366
Ok, I've figured out how to solve this, thanks to this other quetion: https://english.stackexchange.com/questions/11481
The problem is the generator doesn't create right views and model. You'll have to do this modifications by hand.
First in the view _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>
And now add this line to the model, article.rb:
belongs_to :file, :class_name=>'Resource'
Of course you have to modify the show view too. For example:
<section>
<h1>File</h1>
<p>
<%= link_to("Download", @article.file.url) if @article.file %>
</p>
</section>
Would be nice if the generator would do this all automatically but with this you'll have it working.
Upvotes: 2