0

I am new in ruby on rails, I want to call controller method from javascript with multiple parameters. I tried but didn't got output. _applied_candidate.html.erb

<p>Next Status: <span class="fontstyle3">

          <select name="workflow_id" id="workflow_id" onchange="updateItem('workflow_id', <%= applied_candidate.id %>, <%= job.id %>)">         
            <% data.each do | d | %>                  
                <option value="">Please select</option>
                <% d.next_step.split(',').each do | s | %>
                  <% data1 = CandidateWorkFlow.select(:workflow_step).where("step_id = ?",s) %>                   
                   <% data1.each do |l| %>
                      <option value=<%= s%>> <%= l.workflow_step %> </option>          
                    <% end %>
                  <% end %>                   
            <% end %>
          </select>  
        </span>
        </p>


 <script type="text/javascript">
    function updateItem(item, userID, jobID) {
    var e = document.getElementById(item);
    var val = e.options[e.selectedIndex].value; 
    new Ajax.Request('/jobs/update_work_flow', { 
                  method: 'post',
                  parameters: { selected_id: item, u_id: userID, job_id: jobID }
                });


};</script>

routes.rb

resources :jobs do
    get :update_work_flow,  on: :collection 

end

jobs_controller.rb

def update_work_flow
redirect_to root_path

end

How to check controller method called or not

1 Answer 1

2

On routes.rb, Please make the following change,

resources :jobs do
    post :update_work_flow,  on: :collection 

In Js, you have specified as 'post' method, while in routes, you have specified a 'get' method. Try changing to post and the code should work.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for reply, I replaced get with post but still it is not working. if you have another option for this task, please suggest me ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.