Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. # after doing an edit via update, it won't redirect_to show, it stays on edit, I am using ajax
  2. # in the view
  3. # so here is the code:
  4. #
  5. # here is how I have the routes:
  6. map.resources :patrocinios
  7. #...
  8. map.connect ':controller/:action/:id'
  9. map.connect ':controller/:action/:id.:format'
  10.  
  11. # here is the controller:
  12.  
  13. def edit
  14. @patrocinio = Patrocinio.find(params[:id])
  15. respond_to do |format|
  16. format.html # edit.html.erb
  17. format.xml { render :xml => @patrocinio }
  18. end
  19. end
  20.  
  21. def update
  22. @patrocinio = Patrocinio.find(params[:id])
  23. respond_to do |format|
  24. if @patrocinio.update_attributes(params[:patrocinio])
  25. flash[:notice] = 'Patrocinio was successfully updated.'
  26. format.html { redirect_to(@patrocinio) }
  27. format.xml { head :ok }
  28. else
  29. format.html { render :action => "edit" }
  30. format.xml { render :xml => @patrocinio.errors, :status => :unprocessable_entity }
  31. end
  32. end
  33. end
  34.  
  35. # here is the view:
  36.  
  37. <h1>Editing Patrocinio: <%= @patrocinio.id %> </h1>
  38.  
  39. <% form_remote_for(@patrocinio) do |f| %>
  40. <%= f.error_messages %>
  41.  
  42. <p>
  43. <%= f.label :logotipo_id %><br />
  44. <%= f.select :logotipo_id, @logotipos, :prompt => "Select one..." %></td>
  45. </p>
  46.  
  47. <p>
  48. <%= observe_field( :patrocinio_logotipo_id,
  49. :url => { :action => :update_image_div },
  50. :frequency => 1.0,
  51. :update => 'logo_field_div',
  52. :with => :logotipo_id ) %>
  53.  
  54.  
  55. <div id='logo_field_div'>
  56. </div>
  57.  
  58. </p>
  59.  
  60. <p>
  61. <%= f.submit 'Update' %>
  62. </p>
  63. <% end %>
Add Comment
Please, Sign In to add comment