samedi 14 octobre 2017

rails edit_model_name_url(@model_name) does not take me to edit page

i want to redirect to edit page on dropdown change event from new page. if data is present in database for selected week then display that data in edit page. for this i use ajax method . this is working perfectly

 $('select#weeknumber').on('change', function(event) {
  var selected_id= $(this).val();
  $.ajax({
    type:'post',
    url:'/clients/changeweek/',
     data:{ week: selected_id}       

});      

});

Inside my controller i have a changeweek method from which i want to redirect to edit page with specific id.For this i used redirect_to which creates the link which i want but the edit page did not load it still remains on new.html.erb

def changeweek 
@weekcheck = Client.where('weeknumber = ?',params[:week])

   if @weekcheck.nil?
    @clientdata = Client.new(params[:weeknumber] => params[:week])
    redirect_to new_client_path(@client)
    else
    @client = Client.find_by('weeknumber = ?',params[:week])
    redirect_to edit_client_url(@client)
    end

end

Please help me

Aucun commentaire:

Enregistrer un commentaire