ruby on rails - Date not saving to database when using form_for -


i've seen bunch of questions this, when looked @ them, either using jquery or people saving dates string. in model :deadline in date format. in doubt whether should make date or datetime maybe that's went wrong. anyway have form:

<%= form_for(@task) |f| %>   <%= render 'shared/error_messages', object: f.object %>   <div class="field">     <%= f.text_field :description, placeholder: "what do?" %>   </div>   <div class="input">     <%= f.date_field :deadline %>   </div>   <%= f.submit "create task", class: "btn btn-small btn-default" %> <% end %> 

the form appears normal, can pick date. however, doesn't save date database. i've tried

<%= f.date_select :deadline %> 

as well.

should change :deadline type, maybe leave string , parse when it's time display it?

edit: tasks_controller.rb

class taskscontroller < applicationcontroller   before_action :signed_in_user   before_action :correct_user,   only: :destroy    def create     @task = current_user.tasks.build(task_params)     if @task.save       flash[:success] = "task created!"       redirect_to root_url     else       @feed_items = []       render 'static_pages/home'     end   end   def destroy     @task.destroy     redirect_to root_url   end    private      def task_params       params.require(:task).permit(:description)     end      def correct_user       @task = current_user.tasks.find_by(id: params[:id])       redirect_to root_url if @task.nil?     end end 

please update strong parameters in tasks_controller.rb

def task_params   params.require(:task).permit(:description, :deadline) end 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -