Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. Rails.application.routes.draw do
  2. resources :surroundings
  3.  
  4. resources :headings
  5.  
  6. resources :options
  7.  
  8. resources :categories
  9.  
  10. resources :mains
  11.  
  12. resources :properties do
  13.  
  14.  
  15. resources :images, only: [:index, :new, :create, :destroy] do
  16. collection do
  17. get 'update_main'
  18. end
  19.  
  20. end
  21.  
  22.  
  23. get 'addoption'
  24. post 'postoption'
  25.  
  26. end
  27.  
  28. root 'search#main'
  29. get 'main' =>'search#main'
  30.  
  31. class ImagesController < ApplicationController
  32.  
  33.  
  34. def new
  35. redirect_to property_images_path #used for trouble shooting - does not redirect
  36. @image = Image.new
  37.  
  38. end
  39.  
  40.  
  41. def index
  42. @images = Property.find(params[:property_id]).images
  43. end
  44.  
  45.  
  46.  
  47. def update_main
  48. #set the current main image to false
  49. r=Property.find(params[:property_id]).images.where("main" => true).first
  50. r.main=false unless r.nil?
  51. r.save unless r.nil?
  52. @image=Image.find(params[:main])
  53. @image.main=true;
  54. @image.save
  55. redirect_to property_images_path, notice: "The Image has been uploaded."
  56. end
  57.  
  58.  
  59. def create
  60. @image = Image.new(image_params)
  61. @image.property_id=params[:property_id]
  62. if @image.save
  63. redirect_to property_images_path, notice: "The Image has been uploaded."
  64. else
  65. render "new"
  66. end
  67. end
  68.  
  69. def destroy
  70. @image = Image.find(params[:id])
  71. @image.destroy
  72. redirect_to property_images_path, notice: "The Image has been deleted."
  73. end
  74.  
  75. private
  76. def image_params
  77. params.require(:image).permit(:attachment,:property_id)
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement