newbie in rails,
i'm trying to use refinerycms in my rails app, refinery already available to upload an images to the database, i'm trying to combine it to an extension that i use, "events" extension, so when i create a new events that should create 2 object, events to refinery_event table which have image_id as a foreign key for images id, and the event image attribute that will be saved to refinery_images,
i've add a migrations image_id column to refinery_event and put this relation to event.rb models
belongs_to :image_id, :class_name => '::Refinery::Image'
add this in event_controller.rb
def image_params
params.require(:event).permit(:image_name, :image_size, :image_width, :image_height, :created_at, :updated_at)
end
def new
@event = Event.new
@image_id = Refinery::Image.new
end
def create
@event = Event.new(event_params)
@image_id = Refinery::Image.new(image_params)
if @event.save
begin
Mailer.notification(@event, request).deliver_now
rescue => e
logger.warn "There was an error delivering the event notification.\n#{e.message}\n"
end
if Event.column_names.map(&:to_s).include?('email')
begin
Mailer.confirmation(@event, request).deliver_now
rescue => e
logger.warn "There was an error delivering the event confirmation:\n#{e.message}\n"
end
else
logger.warn "Please add an 'email' field to Event if you wish to send confirmation emails when forms are submitted."
end
redirect_to refinery.thank_you_events_events_path
else
render :action => 'new'
end
end
def event_params
params.require(:event).permit(:nama, :deskripsi, :periode_start, :periode_end, :lokasi, :jumlah, :gender_id, :age_id, :event_types_id, :des_acara, :key_kata, :tipe_sponsor, :dana, :exposure, :enggagement, :image_id)
end
and this is the form looks like,
<%= form_for [refinery, :events, @event], :html => { :multipart => true } do |f| %>
<%= render '/refinery/admin/error_messages',
:object => @event,
:include_object_name => true %>
<div class='field nama_field string_field'>
<%= f.label :nama %>
<%= f.text_field :nama %>
</div>
<div class='field deskripsi_field text_field'>
<%= f.label :deskripsi %>
<%= f.text_area :deskripsi, :rows => 8 %>
</div>
<div class="field">
<p>
<%= f.file_field :image_id %>
</p>
</div>
<div class='actions'>
<%= f.submit t('.send') %>
</div>
<% end %>
and i'm stuck what else ? how to make this form work? anyone can teach me?
thanks..
As answered here: https://groups.google.com/forum/#!msg/refinery-cms/5RbAD079IPc/nVFGKdnfAQAJ
You can use the built in image picker, as we can see if we use the generator:
This creates the following admin controller:
And the following template: