Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <%= form_for(@imagevote) do |f| %>
  2. <% @miniature.collections(:photo).each do |collection| %>
  3.  
  4. <% if collection.photo.exists? %>
  5. <td><div class="photo1">
  6.  
  7. <%= link_to image_tag(collection.photo.url(:thumb), :retina => true), collection.photo.url(:original), :retina => true, :class => "image-popup-no-margins" %>
  8. <%= f.radio_button(:collection_id, collection.id) %>
  9. <%= f.hidden_field :voter_id, :value => current_user.id %>
  10. <%= f.hidden_field :voted_id, :value => collection.user_id %>
  11. <%= f.hidden_field :miniature_id, :value => @miniature.id %>
  12.  
  13. <p>Painted by <%= link_to collection.user.name, collection.user %></p>
  14. </div></td>
  15. <% end %>
  16. <% end %>
  17. <%= f.submit "Vote" %>
  18. <% end %>
  19.  
  20. <%= link_to "See more and change your vote.", edit_imagevote_path(:miniature_id => @miniature, :voter_id => current_user.id) %>
  21.  
  22. class ImagevotesController < ApplicationController
  23.  
  24. respond_to :html, :js
  25.  
  26. def new
  27. @imagevote = Imagevote.new
  28. @miniature = Miniature.find(params[:miniature_id])
  29. end
  30.  
  31. def edit
  32. @imagevote = Imagevote.find_by_miniature_id_and_voter_id(params[:miniature_id],params[:voter_id])
  33. @miniature = Miniature.find(params[:miniature_id])
  34. end
  35.  
  36. def create
  37. @imagevote = Imagevote.new(imagevote_params)
  38. if @imagevote.save
  39. flash[:success] = "Vote registered"
  40. redirect_to :back
  41. else
  42. flash[:success] = "Vote not registered"
  43. redirect_to :back
  44. end
  45. end
  46.  
  47. def update
  48. @imagevote = Imagevote.find(params[:id])
  49. if @imagevote.update_attributes(imagevote_params)
  50. flash[:success] = "Vote changed."
  51. redirect_to :back
  52. else
  53. redirect_to :back
  54. end
  55. end
  56.  
  57. private
  58.  
  59. def imagevote_params
  60. params.require(:imagevote).permit(:collection_id, :voter_id, :voted_id, :miniature_id)
  61. end
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement