I have a refinerycms app with the community blog engine installed on it. I would like to add an image field to the blog_post so that I can choose a main image for the post and have it show in my views.
I've tried adding an image field, no joy. Then I looked at one of my other custom engines with an image field and that uses image_id to link to the main image table, so I tried adding an image_id field instead and the editing the blog_post model to have the same 'belongs_to" line. THe edit page for the blog loads, and the image picker partial works, but when I hit save it looks like nothing is being sent to my table.
One thing that concerns me is when I created my custom engine with the image field, I specified it as the field type image. This appears to have created the image_id field on the back end, and set everything up so I can still reference an image class. Adding an image field to the blog didn't do that, just created a field type called image. When inspecting the tables for my custom engine, there is no field type called image, so somewhere there is some transformation magic that I am not able to recreate.
Currently I have the following code:
Created this migration:
class AddPictureToBlog < ActiveRecord::Migration
def self.up
add_column :blog_posts, :main_image_id, :integer
end
def self.down
remove_column :blog_posts, :main_image_id
end
end
Added this to the blog_post model:
belongs_to :main_image_id, :class_name => 'Image'
and have this on the view:
<%= f.label :main_image_id -%>
<%= render :partial => "/shared/admin/image_picker", :locals => {
:f => f,
:field => :main_image_id,
:image => @blog_post.main_image_id,
:toggle_image_display => false
} %>
The custom engine doesn't even refer to the _id field, so I dont know which links im missing here. Any help would be greatly appreciated. It may not be a refinerycms specific problem at all - I am new at rails so there maybe some basics im missing here.
Thanks!