我正在尝试使用format.html,但它说的是我没有足够的参数。它在Rails 4.1之前工作我相信。我刚刚升级到4.2.1,现在它无法正常工作。
if(!params[:search].blank?)
@company = Company.where("comp_name LIKE ?", "#{params[:search]}%")
@main_company = @company.first
if(@main_company.nil?)
flash.now[:danger] = "Invalid Company Name"
@company = []
else
respond_to do |format|
format.json do
results = @company.map do |company|
{ comp_name: company.comp_name }
end
render json: results
end
format.html{redirect_to company_path(@main_company)}
# format.html { redirect_to company_path(@main_company) }
end
end
else
@company = []
end
我收到错误:
wrong number of arguments (2 for 1)
Extracted source (around line #18)
16 render json: results
17 end
18 format.html{redirect_to {company_path(@main_company)}}
19 # format.html { redirect_to company_path(@main_company) }
20 end
21 end
Rails.root: /Users/dariustran/Documents/rails_projects/ferch
Application Trace | Framework Trace | Full Trace
app/controllers/static_pages_controller.rb:18:in `block (2 levels) in home'
app/controllers/static_pages_controller.rb:11:in `home'
请帮忙!谢谢!
答案 0 :(得分:0)
以下代码应该适合您。
#This should be in modal of company
def search_company_by_name params
if params[:search]
l = Company.where("comp_name LIKE '%#{params[:search]}%'")
else
[]
end
end
# controller's action
res = Company.search_company_by_name params
respond_to do |format|
format.json {render json: res}
end
我希望有所帮助。