I have right now two models (There will be more later, therefor I use one Polymorhpic model.
The Polymorhpic table is called Events,
and the model has this:
belongs_to :eventable, :polymorphic => true
Then, the Users table, which has many events:
has_many :events, :as => :eventable
The Users table is a Devise table, so when a event is created, i simply want to pass the user id and type to Events:
def create
event_params[:eventable] = current_user
@event = Event.new(event_params)
if @event.save
redirect_to @event
else
render text: @event
end
end
private
def event_params
params.require(:event).permit(:name, :text, :start_date, :end_date, :eventable)
end
The Event is saved, but i do not get the eventable-fields filled ...
current_user is defined, so thats no problem.
Should i pass params[:eventable_id] and params[:eventable_type] manual?
If so, in which format should eventable_type be, so that it will work when the i get the users events?