我有以下Ruby形式:
.search_client_users
.main_form.client_emails
= simple_form_for(:domainNameSwap, url: { action: "update" }, html: { class: "search_form", method: :put }) do |f|
.input-row
= f.input :oldDomain, :label => "Old Domain Name", input_html: {name: 'search_term'}
.submit-row
.row
.col-xs-5
.submit
= f.submit "Update domains", id: "submit", :class => "btn btn-primary submit"
routes.rb的相关位:
resources :client_emails, :path => 'client_emails', :controller => 'client_emails' do
collection do
get 'lookup'
get 'client_list'
put 'update_emails'
end
end
该表单通常可以按预期运行,但是当我单击“提交”时,它会转到:http://localhost:3000/admin/client_emails/update
,这似乎是合理的,但显示错误:
Missing template admin/client_emails/destroy, admin/base/destroy, application/destroy with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml]}.
该路由要销毁什么?在控制器中,肯定是要使用destroy方法而不是update方法(两者都存在)
我可能还需要显示一些其他信息,但是我不确定它是什么...
添加控制器代码。可能比必要的更多...
class Admin::ClientEmailsController < Admin::BaseController
DEFAULT_SEARCH_RESULTS_LIMIT = 300
def index
@cep_landing_page = ClientLandingPage.find_by_description("CEP")
@yt_landing_page = ClientLandingPage.find_by_description("YouthTruth")
@roster_data_instructions = ClientLandingPage.find_by_description("YouthTruth Roster Data Instructions")
puts "index"
end
def new
@client = Client.new
puts "new"
end
def update
puts "BAR"
newDomClients = Client.where("email like '%"+ newDom + "'")
end
redirect_to admin_clients_path
end
def destroy
puts "foobie"
puts params
end
def client_list
clients = SearchClientUsers.matching(params[:search_term])
@clients = clients.limit(search_results_limit)
@search_results_count_message = if params[:search_term].blank?
"Showing #{@clients.count} of #{clients.count} client users"
else
"Showing #{@clients.count} of #{clients.count} client users matching the search criteria"
end
render layout: false
end
private
def client_params
params.require(:client).permit(:email, :password, :password_confirmation, :first_name, :last_name, :organisation, :assigned_team)
end
def search_results_limit
Integer(ENV['CLIENT_SEARCH_RESULTS_LIMIT'] || DEFAULT_SEARCH_RESULTS_LIMIT)
end
end
def user_params
params.require(:client).permit(:password, :password_confirmation)
end
答案 0 :(得分:0)
这似乎是因为.main_form
和.search_client_users
的组合,如果我将.main_form
完全删除,则将其从.main_form.client_emails
转到{{1 }}(据我所知,这是完全等效的),它似乎可以正常工作...
如果有人可以解释为什么会起作用,或者这里发生了什么,我会批准这个答案...但是目前,我将把它留给后代使用...