ruby on rails - Why my data won't save to SQL? -
i'm quite new ruby on rails. i'll playing around it. actually, i'm trying create form title , daterangepick (bootstrap).
so, works fine until now. have 1 problem: data don't save in database. everytime submit form creates new record, inserts automatically "created_at" etc. 2 fields "title" , "date" empty every time... don't know fault is. may of can me? pls give me answer explication, cause i'm trying understand whats going on.
here code (i'm using simple_form gem)
new.html.erb:
<%= simple_form_for @event |f| %> <%= f.input_field :title, required: false %> <%= f.input :date, input_html: { class: "daterange" }, required: false %> <%= f.button :submit %> <% end %> <script type="text/javascript"> $(document).ready(function() { $('input[class="string optional daterange"]').daterangepicker( { locale: { format: 'yyyy-mm-dd' }, startdate: '2013-01-01', enddate: '2013-12-31' }, function(start, end, label) { alert("a new date range chosen: " + start.format('yyyy-mm-dd') + ' ' + end.format('yyyy-mm-dd')); }); }); </script>
events_controller.rb:
class eventscontroller < applicationcontroller def index @event = event.all end def show end def new @event = event.new end def create @event = event.new(event_params) if @event.save redirect_to @event else render 'new' end end private def event_params params.permit(:title, :date) end end
i think should enough... sure can post more of code if wish, think problem has here somewhere, since works fine... routes fines, can insert, redirects me /events/:id ... database keeps beeing empty. thank !!!
you need require
in params:
def event_params params.require(:event).permit(:title, :date) end
Comments
Post a Comment