12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- class ContactMessagesController < ApplicationController
- before_action :set_contact_message, only: [:show, :edit, :update, :destroy, :unread, :readed]
-
-
- def index
- @contact_message = ContactMessage.new
- end
-
-
- def create
- @contact_message = ContactMessage.new(contact_message_params)
- if user_signed_in?
- @contact_message.user = current_user
- end
- @contact_message.unread = true
- to_address = Info.first.contact_email
- respond_to do |format|
- if @contact_message.save
- UserMailer.contact_message(@contact_message, to_address).deliver
- format.html { redirect_to contact_messages_path, notice: (t 'contact.delivered') }
- format.json { render action: 'show', status: :created, location: @contact_message }
- else
- format.html { redirect_to contact_path, alert: (t 'contact.not_delivered') }
- format.json { render json: @contact_message.errors, status: :unprocessable_entity }
- end
- end
- end
- def show
- @contact_message.unread = false
- @contact_message.save
- end
-
- def readed
- @contact_message.unread = false
- respond_to do |format|
- if @contact_message.save
- format.html { redirect_to admin_contact_messages_path, notice: 'Contact message marked as readed.' }
- format.json { render action: 'show', status: :created, location: @contact_message }
- else
- format.html { render action: 'new' }
- format.json { render json: @contact_message.errors, status: :unprocessable_entity }
- end
- end
- end
-
- def unread
- @contact_message.unread = true
- respond_to do |format|
- if @contact_message.save
- format.html { redirect_to admin_contact_messages_path, notice: 'Contact message marked as unread.' }
- format.json { render action: 'show', status: :created, location: @contact_message }
- else
- format.html { render action: 'new' }
- format.json { render json: @contact_message.errors, status: :unprocessable_entity }
- end
- end
- end
-
-
- def update
- respond_to do |format|
- if @contact_message.update(contact_message_params)
- format.html { redirect_to @contact_message, notice: 'Contact message was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: 'edit' }
- format.json { render json: @contact_message.errors, status: :unprocessable_entity }
- end
- end
- end
-
-
- def destroy
- @contact_message.destroy
- respond_to do |format|
- format.html { redirect_to contact_messages_url }
- format.json { head :no_content }
- end
- end
- private
-
- def set_contact_message
- @contact_message = ContactMessage.find(params[:id])
- end
-
- def contact_message_params
- params.require(:contact_message).permit(:title, :email, :content, :unread, :user_id)
- end
- end
|