意见/反馈/searchfeedback.html.erb :
我的搜索表格:
<%= form_tag(search_feedback_feedback_path(:id), :method => :get) do %>
<%= text_field_tag :token_no %>
<%= submit_tag 'Search' %>
<% end %>
app/config/routes.rb 文件:
resources :feedbacks do
member do
get :search_feedback
end
end
match '/feedbackresult' => 'feedbacks#searchedfeedback'
在 feedbacks_controller.rb 文件中:
def search_feedback
if params[:token_no]
@result_feedback = Feedback.find_by_token(params[:token_no])
redirect_to feedbackresult_path
end
end
意见/反馈/ searchedfeedback.html.erb:
Your Result found : <%= @result_feedback.name %>
在这里我收到以下错误:
NoMethodError in Feedbacks#searchedfeedback
Showing C:/Users/PROJ/app/views/feedbacks/searchedfeedback.html.erb where line #1 raised:
undefined method `name' for nil:NilClass