Upon clicking delete I want my page to redirect to the current user's poll. This something like this. questions_controller.rb:
def destroy
@poll_id = Question.find(param[:poll_id])
@question.destroy
respond_to do |format|
format.html { redirect_to user_poll_url(current_user.id, @question.poll_id), notice: "Question was successfully destroyed." }
format.json { head :no_content }
end
end
The Questions_controller's content is the same as the rails generated with the exception of the above change.
the question_controller has the poll_id as a paramter. How do I retrieve it's current value to use for redirection.
def question_params
params.require(:question).permit(:poll_id, :title, :description)
end
routes.rb
resources :users do
resources :polls
end
resource :polls do
resources :questions
end
The error i'm getting is:
ActiveRecord::RecordNotFound in QuestionsController#destroy
Couldn't find Question without an ID
Extracted source (around line #52):
# DELETE /questions/1 or /questions/1.json
def destroy
@poll_id = Question.find(param[:poll_id])
session[:return_to] ||= request.referer
@question.destroy
with line 52 being @poll_id = Question.find(param[:poll_id])