Ruby On rails: Problem related to routingy

1 Min. Read
Oct 9, 2014

 Rails Ruby JS Proposal routingy

Problem


I have to edit a proposal among many proposals. When we click edit button a popup appears with all fields filled. There is a button ‘Verify’ to preview the proposal before sending to client via Email.

Suppose URL to edit proposal is proposals/:id/edit  It shows a popup with all fields filled and a ‘Send’ and ‘Verify’ button. URL for verify is proposals/:id/verify-proposal. When user edits and sends data is saved and an email is sent and the same form is rendered back filled to user with success message. Now when I click the verify button, routing error encountered, the application invokes update action throwing error.

1
ActiveRecord::RecordNotFound (Couldn't find Proposal with 'id'=verify-proposal): app/controllers/proposals\_controller.rb:66:in update'

Reason:: now URL where AJAX request is being sent is proposals/verify-proposal

Behind Scene: In routes.rb i have routed two URLs to same actions within which http method is checked and processed accordingly. URLs proposals/:id/verify-proposal (To verify edit of Individual Proposal) and proposals/verify-proposal (To verify newly to be created Proposal) are routed to verify_proposal action. To verify/preview I have used AJAX method to send data as

1
2
3
4
5
6
7
varformData= $('.form').serializeArray();
$.ajax({
url: 'verify-proposal',
type: 'post',
data:formData,
success: function (html) {
//Open Popup window then verify HTML comes from server ... ... ... } });
1
2
3
4
5
6
7
8
9
# routes.rb 
resources :proposals do
  collection do 
    post :verify_proposal, path: 'verify-proposal'
  end
  member do
    patch :verify_proposal, path: 'verify-proposal'
  end
end

The solution is

1
2
3
4
5
6
7
varformData= $('.form').serializeArray();
$.ajax({
url: '\bids\' + idOfBid + '\verify-proposal',
type: 'post',
data:formData,
success: function (html) {
//Open Popup window then verify HTML comes from server ... ... ... } });

You might also like

Problem I have to edit a proposal among many proposals. When we click edit button a popup appears with all fields filled. There is a button ‘Verify’ to preview the proposal before sending to client via Email. Suppose URL to edit proposal is proposals/:id/edit  It shows a popup with all fields filled and a ‘Send’ and […]


Read More..


Write To Me

Hire me shiva bhusal
We'll never share your email with anyone else.
I'll never share your email with anyone else.