jeudi 21 mai 2015

The action 'Search' cannot be found for InboxController

I am trying to add a search bar. I have also set the path. But everytime I try to click on search it directs me to this error. What is the error in this code?

This is my Inbox_Controller file. It says that the action 'Search' cannot be found in InboxController.

 class InboxController < ApplicationController
 before_action :valid_membership
 before_action :change_password_next_login
 before_action :agreed_to_terms
 before_action :allowed_send_mail?

 layout 'inbox'

 def bulk
 puts params

 ids = params[:bulk_ids]

 if ids
  params[:commit]

  case params[:commit]
    when 'Archive'
      ids.each do |id|
        message = Message.find(id)
        message.archived = true
        message.save()
      end
    when 'Restore'
      ids.each do |id|
        message = Message.find(id)
        message.archived = false
        message.save()
      end
    else
      puts 'invalid action!!'
  end


  if params[:folder] != ''
    redirect_to inbox_index_path(folder: params[:folder])
  else
    redirect_to inbox_index_path
  end
 else
  flash[:alert] = t('errors.inbox.no_emails_selected')
  redirect_to :back
 end
 end

def index
per_page = 10
page = params[:page] ? params[:page] : 1

  case params[:folder]
  when 'archive'
    @messages = current_user.archived_messages(page, per_page)
  when 'drafts'
    @messages = current_user.draft_messages(page, per_page)
  when 'sent'
    @messages = current_user.sent_messages(page, per_page)
  else
    @messages = current_user.received_messages(page, per_page)
  end

  end

  def reply
  original = Message.find(params[:id])
  @quoted = "\n\nOn #{original.sent_time.strftime("%m/%d/%y %-I:%M %p")}, # {original.from.full_name} wrote:\n----------------\n#{original.body}"
@message = Message.new(
    :parent => original,
    :to => original.from,
    :subject => "RE: #{original.subject}",
    :body => @quoted,
)

render :compose
end

def move
@message = Message.find(params[:id])
folder = params[:destination]

case folder
  when 'archive'
    @message.archived = true
  else
    @message.archived = false
end

unless @message.save
  puts @message.errors.full_messages
end

redirect_to inbox_index_path(folder: folder)
end

def show
@message = Message.find(params[:id])

if !@message.read? && @message.to == current_user
  @message.read_time = DateTime.now
  unless @message.save
    puts @message.errors.full_messages
  end
end
end

def edit
@message = Message.find(params[:id])
@message.to_name = @message.to.full_name
render 'compose'
end

  def compose
   @message = Message.new
   if(params[:id])
     @message.to = Mentor.find(params[:id])
   end

  end

  def create
    if(params[:message] && !params[:message][:id].empty?)
      @message = Message.find(params[:message][:id])
      @message.assign_attributes(message_params)
    else
      @message = Message.new(message_params)
    end

     if params[:parent_id] && !params[:parent_id].empty?
     @message.parent = Message.find(params[:parent_id])
     @message.replied_to_time = Time.now
    end
    @message.from = current_user

    draft = params[:draft]

    if draft
      @message.draft = true
    else
      @message.sent_time = Time.now
      @message.draft = false
    end

     # puts @message.as_json
    if can_send_mail
      if @message.save
        if !draft
          if current_user_or_guest.mentee?
            current_user.credits += -1
            current_user.save
          end

         UserMailer.inmail_notification(@message).deliver
        end

        redirect_to inbox_index_path(folder: draft ? 'drafts' : 'inbox'), notice: "Message successfully #{draft ? 'saved' : 'sent'}."
      else
        flash.now[:alert] = 'All email fields need to be filled out prior to sending/saving.'
        render 'compose'
      end
    else
      flash.now[:alert] = 'You do not have enough credits to send any more    InMail to Game Changers.'
      render 'compose'
    end
   ActivityLog.create(userid: current_user.id, points: 500, typeof: "message")
  end 

  def allowed_send_mail?
    unless !current_user.admin?
      msg = "You are not authorized to access this page!"
     show_error(msg)
   end
  end

  def profile_complete
    return true if current_user.mentor?

    unless current_user.profile_complete?
      flash[:alert] = t('errors.inbox.incomplete_profile')
      redirect_to edit_user_registration_path
    end
  end

  def message_params
    params.require(:message).permit(:id, :to_name, :to_id, :subject, :body)
  end
end

Aucun commentaire:

Enregistrer un commentaire