修改访问poll#index报ArgumentError

This commit is contained in:
sw 2015-01-12 16:56:53 +08:00
parent 1c24a306fe
commit 475b046898
3 changed files with 91 additions and 7 deletions

View File

@ -0,0 +1,89 @@
class PollController < ApplicationController
before_filter :find_poll_and_course, :only => [:edit,:update,:destory]
before_filter :find_container, :only => [:new,:create, :index]
def index
if @course
@polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}")
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
elsif @project
#项目的问卷调查相关代码
end
end
def show
@poll = Poll.find params[:id]
end
def new
if @course
option = {
:polls_name => l(:label_poll_new),
:polls_type => @course.class.to_s,
:polls_group_id => @course.id,
:polls_status => 1,
:user_id => User.current.id,
:published_at => Time.now,
:closed_at => Time.now,
:polls_description => ""
}
@poll = Poll.create option
if @poll
respond_to do |format|
format.html{render :layout => 'base_courses'}
end
end
elsif @project
#项目的问卷调查相关代码
end
end
def create
end
def edit
end
def update
@poll.polls_name = params[:polls_name]
if @poll.save
respond_to do |format|
format.html { redirect_to poll_index_url(:polls_type => @course.class.to_s, :polls_group_id => @course.id) }
end
else
end
end
def destroy
if @poll.destroy
respond_to do |format|
format.js
end
end
end
private
def find_poll_and_course
@poll = Poll.find params[:id]
@course = Course.find @poll.polls_group_id
rescue Exception => e
render_404
end
def find_container
if params[:polls_type] && params[:polls_group_id]
case params[:polls_type]
when "Course"
@course = Course.find_by_id params[:polls_group_id]
when "Project"
@project = Project.find_by_id params[:polls_group_id]
end
else
render_404
end
end
end

View File

@ -1,7 +1 @@
<% @polls.each do |poll|%>
<%= poll.id%>#####<%= poll.polls_name%>
<%= link_to l(:button_edit), edit_poll_path(poll.id)%>
<%= link_to(l(:button_delete), poll,
method: :delete, :confirm => l(:text_are_you_sure), :remote => true ) %>
<br/>
<%end%>
1111111111111

View File

@ -2241,4 +2241,5 @@ zh:
label_quote_resource_failed: ",此资源引用失败! "
label_file_lost: 以下无法成功下载,请联系相关人员重新上传:
label_file_exist: 该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载
label_poll_new: 未命名问卷