這是我的第一個ror應用程序。 我有主頁:home.html.erb
我有形式那裏。形式中的第一個參數不能包含零或爲空ror
<%= form_for(@lead ,:html => {:class => 'check_form'}) do |f| %>
<%= f.text_field :phone, placeholder: 'phone' %>
<%= f.submit "Check car status", class: "btn btn-large btn-primary" %>
<% end %>
背景故事:一個客戶(我叫他主管可以輸入自己的電話號碼,並檢查它現在正在修理自己的汽車的狀態)
眼下這種觀點home.html.erb
由static_pages_controller
class StaticPagesController < ApplicationController
def home
end
def help
end
def about
end
def contact
end
end
我也LeadsController
class LeadsController < ApplicationController
#before_action :signed_in_user, only: [:index, :edit, :update]
#before_action :correct_user, only: [:edit, :update]
before_action :admin_user, only: [:index, :edit, :update, :destroy]
def index
@leads = Lead.paginate(page: params[:page])
end
def destroy
Lead.find(params[:id]).destroy
flash[:success] = "record deleted."
redirect_to leads_url
end
def show
@lead = Lead.find(params[:id])
end
def new
@lead = Lead.new
end
def create
@lead = Lead.new(lead_params)
if @lead.save
#sign_in @lead
flash[:success] = "Request successfully created!"
redirect_to @lead
else
render 'new'
end
end
def edit
@lead = Lead.find(params[:id])
end
def update
@lead = Lead.find(params[:id])
if @lead.update_attributes(status: params[:status])
flash[:success] = "Information updated"
redirect_to leads_url
else
render 'edit'
end
end
private
def lead_params
params.require(:lead).permit(:name, :email, :phone, :car_type,
:car_year, :car_manufacturer, :car_model, :photo1, :photo2, :coords)
end
# Before filters
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def correct_user
@lead = Lead.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
def admin_user
redirect_to(root_url) unless current_user.admin?
end
end
當用戶輸入他的電話號碼查找帶有相同電話號碼的數據庫中的電話號碼並向用戶顯示修復狀態時,我想要執行的操作。 但它會產生一個錯誤: First argument in form cannot contain nil or be empty
所以我得到那form_for(@lead..
這裏@lead是空的。 但是我應該怎麼做才能擺脫這個錯誤。
哪裏是'@ lead'初始化初始化
@lead
? – Makoto@Makoto我不確定它在哪裏初始化。我爲我的leadController添加了代碼。我想現在我不初始化它。 – user2950593