Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- = form_for @ad do |f|
- - if ad.errors.any?
- #error_explanation
- h2
- = pluralize(ad.errors.count, "error")
- | prohibited this ad from being saved:
- ul
- - ad.errors.full_messages.each do |message|
- li= message
- = f.label :locality, "City, country", class: "field-label"
- = f.text_field :locality, class: "input field w-input", placeholder: "Ex: Paris, France", label: false
- = f.label :title, "Job title :", class: "field-label"
- = f.text_field :title , class: "input field w-input", placeholder: "Ex : Solidity Developer Expert...", label: false
- ...
- h3.h3.post The company
- = f.fields_for :company do |c|
- .w-row
- .w-col.w-col-6
- = c.label :name, "Company name", class: "field-label"
- = c.text_field :name, id: "salary-2", class: "field w-input", placeholder: "Ex : CryptoLimbo", label: false
- .w-col.w-col-6
- = c.label :email, "Company email", class: "field-label"
- = c.text_field :email, id: "salary-2", class: "field w-input", placeholder: "Ex : me@cryptolimbo.io", label: false
- ...
- def create
- @ad = Ad.new(ad_params)
- company = Company.find_or_initialize_by(name: params[:ad][:company_attributes][:name])
- @ad.company_id = company.id
- if @ad.valid?
- @ad.save
- redirect_to root_path
- send_notifications(@ad)
- else
- flash[:error] = 'one or more errors in your job'
- render :new
- end
- end
- def update
- respond_to do |format|
- if @ad.update(ad_params)
- format.html { redirect_to @ad, notice: 'Ad was successfully updated.' }
- format.json { render :show, status: :ok, location: @ad }
- else
- format.html { render :edit }
- format.json { render json: @ad.errors, status: :unprocessable_entity }
- end
- end
- end
- private
- def ad_params
- params.require(:ad).permit(:title, :locality, ...,
- company_attributes: [:name, :id, :logo, :logo_cache, :short_description, :long_description, :twitter, :email ]
- )
- end
Add Comment
Please, Sign In to add comment