haml - Rails form keep sending old values after error -
i have form reason keep same values after error. example, if enter name exists, me error , @ same time keep sending old value if change (so have refresh page , lose changes resolve error).
= provide(:title, t(:create_task)) .center = form_for :task, url: tasks_path |f| = render 'shared/big_flash' = render 'task_error_messages' .row.text-center .col-lg-10.col-lg-offset-1.col-md-12.col-sm-12.col-xs-12 .jumbotron %h2= t(:create_task) .row .col-lg-6.col-md-6.col-sm-6.col-xs-12 = f.label t(:par_task_name) %i{class: 'material-icons text-muted', rel: 'tooltip', title: t(:tt_task_new_name)} info_outline = f.text_field 'name', maxlength: 255, class: 'form-control' = f.label t(:par_category) = f.collection_select 'category', category.order(:name), :name, :name, {}, {class: 'form-control'} = link_to t(:btn_modify_categories), categories_modify_path, class: 'btn btn-primary btn-block', data: { confirm: t(:changes_lost_proceed) } = f.label t(:par_task_type) = f.select 'task_type', task::task_types_list, {include_blank: true}, {class: 'form-control', id: 'type_of_task'} = f.label t(:par_score) = f.number_field 'score', min: '0', step: '1', class: 'form-control' .col-lg-6.col-md-6.col-sm-6.col-xs-12 = f.label t(:par_asset) %i{class: 'material-icons text-muted', rel: 'tooltip', title: t(:tt_task_asset)} info_outline = f.file_field 'category' .description = f.label t(:par_description) %i{class: 'material-icons text-muted', rel: 'tooltip', title: t(:tt_task_description)} info_outline = f.text_area 'name', class: 'form-control' = f.check_box 'mathjax' = f.label t(:par_mathjax) %i{class: 'material-icons text-muted', rel: 'tooltip', title: t(:tt_task_mathjax)} info_outline .row .correct_solutions.col-lg-6.col-md-6.col-sm-6.col-xs-12 = f.label t(:par_correct_solutions) #generated_correct_solutions = button_tag t(:btn_add_correct_solution), type: 'button', class: 'btn btn-primary btn-toolbar', id: 'add_correct_solution' .wrong_solutions.col-lg-6.col-md-6.col-sm-6.col-xs-12 = f.label t(:par_wrong_solutions) #generated_wrong_solutions = button_tag t(:btn_add_wrong_solution), type: 'button', class: 'btn btn-primary btn-toolbar', id: 'add_wrong_solution' #close-ended_task{class: 'hidden'} = f.check_box 'random', id: 'randomize_task' = f.label t(:par_random) %i{class: 'material-icons text-muted', rel: 'tooltip', title: t(:tt_task_random)} info_outline #randomize{class: 'hidden'} .row .col-lg-6.col-md-6.col-sm-6.col-xs-12 = f.label t(:par_number_of_solutions) %i{class: 'material-icons text-muted', rel: 'tooltip', title: t(:tt_task_no_random_solutions)} info_outline = f.number_field 'no_random_solutions', min: '1', step: '1', class: 'form-control' .col-lg-6.col-md-6.col-sm-6.col-xs-12 = f.label t(:par_min_number_of_correct_solutions) %i{class: 'material-icons text-muted', rel: 'tooltip', title: t(:tt_task_min_no_random_correct_solutions)} info_outline = f.number_field 'min_no_random_correct_solutions', min: '0', step: '1', class: 'form-control' .btn-group.btn-group-justified.hidden-xs .btn-group = f.submit t(:btn_create_new_task), class: 'btn btn-lg btn-primary btn-toolbar' .btn-group = link_to t(:btn_cancel), '#', class: 'btn btn-lg btn-primary btn-toolbar' .btn-group-vertical.visible-xs = f.submit t(:btn_create_new_task), class: 'btn btn-lg btn-primary' = link_to t(:btn_cancel), '#', class: 'btn btn-lg btn-primary'
and tasks_controller.rb
def new @task = task.new end def create @task = task.new(task_params) @task.user_id = helpers.current_user.id if @task.save flash[:success] = t(:task_created) redirect_to new_task_path else render 'new' end end
any idea problem? don't want clean fields after error, want keep them, on next post, send new values instead.
Comments
Post a Comment