Ruby 找不到InboxController的操作“搜索”
我正在尝试添加一个搜索栏。我也设定了道路。但每次我尝试点击搜索时,它都会指向这个错误。这段代码中的错误是什么 这是我的收件箱\u控制器文件。它表示在InboxController中找不到“搜索”操作Ruby 找不到InboxController的操作“搜索”,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,我正在尝试添加一个搜索栏。我也设定了道路。但每次我尝试点击搜索时,它都会指向这个错误。这段代码中的错误是什么 这是我的收件箱\u控制器文件。它表示在InboxController中找不到“搜索”操作 class InboxController < ApplicationController before_action :valid_membership before_action :change_password_next_login before_action :agreed_t
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
@inbox = Inbox.search(params[:search])
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
此控制器中没有搜索方法,我看到的唯一搜索是调用Inbox.search
要对此进行调试,请从实际执行单击的视图开始。点击真的应该触发InboxController中的操作吗?如果你认为应该,为什么控制器中没有动作?如果没有,那么单击意味着转到另一个实际将处理搜索操作的控制器,在这种情况下,您需要弄清楚为什么单击试图调用InboxController中的方法,而不是所需的控制器。问题可能是您视图中的某个内容或您路由中的某个内容,或者您真的应该在InboxController中使用该方法,无论哪种方式,我建议您尝试至少找出应该发生的事情,然后发布更多代码,说明您认为应该发生的事情与实际发生的事情 因此,当我在控制器中定义不同的搜索方法时,它会显示不同的错误消息。我刚刚在控制器的索引方法中添加了代码。我想不出来。你能帮帮我吗?你能现在检查一下吗?那么你是说你现在有了与你的搜索方法相同的索引方法代码?否则,请显示您现在在搜索方法中的内容以及当前在索引方法中搜索时的错误。我是否应该定义新的搜索方法。是的,按照查看和路由设置的方式,当您单击搜索按钮时,get请求将设置为inbox/search,并路由到inboxsearch,这意味着它正在尝试调用inbox控制器中的方法搜索,但未定义
<%= form_tag inbox_search_path, :method => 'get' do %>
<p>
<%= search_field_tag :Search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
get 'inbox' => 'inbox#index', :as => 'inbox_index'
get 'inbox/show/:id' => 'inbox#show', :as => 'inbox_show'
get 'inbox/compose' => 'inbox#compose', :as => 'inbox_compose'
get 'inbox/compose/:id' => 'inbox#compose', :as => 'inbox_compose_to'
get 'inbox/edit/:id' => 'inbox#edit', :as => 'inbox_edit'
get 'inbox/move' => 'inbox#move', :as => 'inbox_move'
get 'inbox/reply' => 'inbox#reply', :as => 'inbox_reply'
get 'inbox/search' => 'inbox#search', :as => 'inbox_search'
post 'inbox/create' => 'inbox#create'
post 'inbox/bulk' => 'inbox#bulk'