Guest User

Untitled

a guest
May 21st, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. = form_for @ad do |f|
  2. - if ad.errors.any?
  3. #error_explanation
  4. h2
  5. = pluralize(ad.errors.count, "error")
  6. | prohibited this ad from being saved:
  7. ul
  8. - ad.errors.full_messages.each do |message|
  9. li= message
  10. = f.label :locality, "City, country", class: "field-label"
  11. = f.text_field :locality, class: "input field w-input", placeholder: "Ex: Paris, France", label: false
  12.  
  13. = f.label :title, "Job title :", class: "field-label"
  14. = f.text_field :title , class: "input field w-input", placeholder: "Ex : Solidity Developer Expert...", label: false
  15.  
  16. ...
  17.  
  18. h3.h3.post The company
  19. = f.fields_for :company do |c|
  20. .w-row
  21. .w-col.w-col-6
  22. = c.label :name, "Company name", class: "field-label"
  23. = c.text_field :name, id: "salary-2", class: "field w-input", placeholder: "Ex : CryptoLimbo", label: false
  24. .w-col.w-col-6
  25.  
  26. = c.label :email, "Company email", class: "field-label"
  27. = c.text_field :email, id: "salary-2", class: "field w-input", placeholder: "Ex : me@cryptolimbo.io", label: false
  28.  
  29. ...
  30.  
  31. def create
  32. @ad = Ad.new(ad_params)
  33. company = Company.find_or_initialize_by(name: params[:ad][:company_attributes][:name])
  34. @ad.company_id = company.id
  35.  
  36. if @ad.valid?
  37. @ad.save
  38. redirect_to root_path
  39. send_notifications(@ad)
  40. else
  41. flash[:error] = 'one or more errors in your job'
  42. render :new
  43. end
  44. end
  45.  
  46. def update
  47. respond_to do |format|
  48. if @ad.update(ad_params)
  49.  
  50. format.html { redirect_to @ad, notice: 'Ad was successfully updated.' }
  51. format.json { render :show, status: :ok, location: @ad }
  52. else
  53. format.html { render :edit }
  54. format.json { render json: @ad.errors, status: :unprocessable_entity }
  55. end
  56. end
  57. end
  58.  
  59. private
  60.  
  61. def ad_params
  62. params.require(:ad).permit(:title, :locality, ...,
  63. company_attributes: [:name, :id, :logo, :logo_cache, :short_description, :long_description, :twitter, :email ]
  64. )
  65. end
Add Comment
Please, Sign In to add comment