Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 页面中的命名错误#创建_Ruby On Rails - Fatal编程技术网

Ruby on rails 页面中的命名错误#创建

Ruby on rails 页面中的命名错误#创建,ruby-on-rails,Ruby On Rails,大家好,我是RubyonRails新手,在尝试添加新页面时出错。当我单击“创建”时,将显示以下内容 你有一个零的对象,当你没有想到它!你可能有 应为数组的实例。评估时出错 零收款 class PagesController@subject.id)#对于列表视图,它会找到已排序的所有产品 结束 def秀 @page=page.find(params[:id])#它根据产品id查找产品信息,并在show.html中显示 结束 def新 @page=page.new(:subject_id=>@sub

大家好,我是RubyonRails新手,在尝试添加新页面时出错。当我单击“创建”时,将显示以下内容

你有一个零的对象,当你没有想到它!你可能有 应为数组的实例。评估时出错 零收款

class PagesController@subject.id)#对于列表视图,它会找到已排序的所有产品
结束
def秀
@page=page.find(params[:id])#它根据产品id查找产品信息,并在show.html中显示
结束
def新
@page=page.new(:subject_id=>@subject.id)#它在相应的主题(类别)中创建一个新页面(产品)
@page_count=@subject.pages.size+1#所有产品的总(页面)数量
@subjects=Subject.order('position ASC')#显示按升序排列的主题
结束
def创建
#新建位置=参数[:页]。删除(:位置)
@page=page.new(params[:page])#使用表单参数实例化一个新对象
把“我在这里”
如果@page.save#保存对象
#@第页。将位置移动到位置(新位置)
flash[:notice]=“产品已创建。”
重定向到(:action=>'list',:subject\u id=>@page.subject\u id)#如果保存成功,重定向到list操作
其他的
@page_count=@subject.pages.size+1#产品数量已更新
@主题=主题。顺序('位置ASC')
render('new')#如果保存失败,请重新显示表单,以便用户修复问题
结束
结束
定义编辑
@page=page.find(params[:id])#它通过其id查找要编辑的页面
@page_count=@subject.pages.size
@主题=主题。顺序('位置ASC')
结束
def更新
新建位置=参数[:页]。删除(:位置)
@page=page.find(params[:id])#使用参数查找对象
如果@page.update_属性(参数[:page])#更新对象
@第页。将位置移动到位置(新位置)
flash[:注意]=“页面已更新。”
重定向到(:action=>'show',:id=>@page.id,:subject\u id=>@page.subject\u id)#如果更新成功,重定向到列表操作
其他的
@page_count=@subject.pages.size
@主题=主题。顺序('位置ASC')
呈现(“编辑”)#如果保存失败,请重新显示表单,以便用户可以修复问题
结束
结束
def删除
@page=page.find(params[:id])#它根据要删除的id查找页面
结束
def销毁
page=page.find(params[:id])#它根据要销毁的id查找页面
第页。将_移动到_位置(无)
毁灭
flash[:notice]=“产品已销毁。”
重定向到(:action=>'list',:subject_id=>@subject.id)#根据相应的主题(类别)将用户重定向到pages/list.html
结束
私有的
def find_主题
如果参数[:主题\u id]
@subject=subject.find by_id(参数[:subject\u id])
结束
结束
结束
我可以添加没有任何问题的主题,我可以添加没有问题的管理员用户问题是与网页

class SubjectsController < ApplicationController

  layout 'admin'#apply the admin.html layout

  before_filter :confirm_logged_in #confirms if the user is logged in before entering the page

  def index
    list
    render('list')#runs subjects/list.html all list.html are different
  end

  def list
    @subjects = Subject.order("subjects.position ASC")#for the list view it finds the categories sorted,all of them
  end

  def show
    @subject = Subject.find(params[:id])
  end

  def new
    @subject = Subject.new # creates a new subject(category)
    @subject_count = Subject.count + 1
  end

  def create
    new_position = params[:subject].delete(:position)

    @subject = Subject.new(params[:subject]) # instantiate a new object using form parameters

    if @subject.save #save the object

      @subject.move_to_position(new_position)

      flash[:notice] = "Category created."
      redirect_to(:action => 'list')# if save succeeds, redirect to list.html
    else

      @subject_count = Subject.count + 1
      render('new')#If save fails, redisplay the form so user can fix problems
    end
    end


  def edit
    @subject = Subject.find(params[:id])# it finds the subject to be edited
    @subject_count = Subject.count
  end

  def update
    new_position = params[:subject].delete(:position)#if updated it delete the current position

    @subject = Subject.find(params[:id])# find object using form parameters

    if @subject.update_attributes(params[:subject])#update the object(subject)
      @subject.move_to_position(new_position)#new position assigned

      flash[:notice] = "Subject updated."
      redirect_to(:action => 'show', :id => @subject.id)# if update succeeds, redirect to the list action
    else

      @subject_count = Subject.count
      render('edit')# if save fails, redisplay the form so user can fix problems
    end
  end

  def delete
    @subject = Subject.find(params[:id])#it finds thesubjectby the id to be deleted
  end

  def destroy
    subject = Subject.find(params[:id])#it finds the Subject(category)by the id to be destroyed
    subject.move_to_position(nil)
    subject.destroy
    flash[:notice] = "Subject destroyed."
    redirect_to(:action => 'list')# redirected to the list.html 
  end

end
class SubjectsController'list')#如果保存成功,则重定向到list.html
其他的
@subject\u count=subject.count+1
render('new')#如果保存失败,请重新显示表单,以便用户修复问题
结束
结束
定义编辑
@subject=subject.find(params[:id])#它查找要编辑的主题
@subject\u count=subject.count
结束
def更新
新建位置=参数[:主题]。删除(:位置)#如果已更新,则删除当前位置
@subject=subject.find(params[:id])#使用表单参数查找对象
如果@subject.update_属性(参数[:subject])#更新对象(subject)
@主题。移动到新位置(新位置)#分配新位置
flash[:notice]=“主题已更新。”
重定向到(:action=>'show',:id=>@subject.id)#如果更新成功,则重定向到列表操作
其他的
@subject\u count=subject.count
呈现(“编辑”)#如果保存失败,请重新显示表单,以便用户可以修复问题
结束
结束
def删除
@subject=subject.find(params[:id])#它根据要删除的id查找subject
结束
def销毁
subject=subject.find(params[:id])#它根据要销毁的id查找主题(category)
主题。移动到位置(无)
主语:毁灭
flash[:notice]=“主题已销毁。”
重定向到(:action=>'list')#重定向到list.html
结束
结束
这是_form.html.erb,根据框架,错误应该发生在这里 提取的源(第6行附近):

3:
4:   
5:     
6:    
框架跟踪

<
class SubjectsController < ApplicationController

  layout 'admin'#apply the admin.html layout

  before_filter :confirm_logged_in #confirms if the user is logged in before entering the page

  def index
    list
    render('list')#runs subjects/list.html all list.html are different
  end

  def list
    @subjects = Subject.order("subjects.position ASC")#for the list view it finds the categories sorted,all of them
  end

  def show
    @subject = Subject.find(params[:id])
  end

  def new
    @subject = Subject.new # creates a new subject(category)
    @subject_count = Subject.count + 1
  end

  def create
    new_position = params[:subject].delete(:position)

    @subject = Subject.new(params[:subject]) # instantiate a new object using form parameters

    if @subject.save #save the object

      @subject.move_to_position(new_position)

      flash[:notice] = "Category created."
      redirect_to(:action => 'list')# if save succeeds, redirect to list.html
    else

      @subject_count = Subject.count + 1
      render('new')#If save fails, redisplay the form so user can fix problems
    end
    end


  def edit
    @subject = Subject.find(params[:id])# it finds the subject to be edited
    @subject_count = Subject.count
  end

  def update
    new_position = params[:subject].delete(:position)#if updated it delete the current position

    @subject = Subject.find(params[:id])# find object using form parameters

    if @subject.update_attributes(params[:subject])#update the object(subject)
      @subject.move_to_position(new_position)#new position assigned

      flash[:notice] = "Subject updated."
      redirect_to(:action => 'show', :id => @subject.id)# if update succeeds, redirect to the list action
    else

      @subject_count = Subject.count
      render('edit')# if save fails, redisplay the form so user can fix problems
    end
  end

  def delete
    @subject = Subject.find(params[:id])#it finds thesubjectby the id to be deleted
  end

  def destroy
    subject = Subject.find(params[:id])#it finds the Subject(category)by the id to be destroyed
    subject.move_to_position(nil)
    subject.destroy
    flash[:notice] = "Subject destroyed."
    redirect_to(:action => 'list')# redirected to the list.html 
  end

end
3: <table summary="Products form fields">
4:   <tr>
5:     <th><%= f.label(:subject_id, "Category") %></th>
6:  <td><%= f.select(:subject_id, @subjects.collect {|s| [s.name, s.id]}) %></td>  </tr>

<%= error_messages_for(@pages) %>

<table summary="Products form fields">
  <tr>
    <th><%= f.label(:subject_id, "Category") %></th>
    <td><%= f.select(:subject_id, @subjects.collect {|s| [s.name, s.id]}) %></td>  </tr>
  <tr>
    <th><%= f.label(:product_name) %></th>
    <td><%= f.text_field(:product_name) %></td>
  </tr>
  <tr>
    <th><%= f.label(:description) %></th>
    <td><%= f.text_area(:description) %></td>
  </tr>
  <tr>
    <th><%= f.label(:min_description) %></th>
    <td><%= f.text_area(:min_description) %></td>
  </tr>
  <tr>
    <th><%= f.label(:brand) %></th>
    <td><%= f.text_field(:brand) %></td>
    <tr>
    <th><%= f.label(:quantity) %></th>
    <td><%= f.text_field(:quantity) %></td>
  </tr>
  <tr>
    <th><%= f.label(:price) %></th>
    <td><%= f.text_field(:price) %></td>
  </tr>
  <tr>
    <th><%= f.label(:size) %></th>
    <td><%= f.text_field(:size) %></td>
  </tr>
  <tr>
    <th><%= f.label(:head_size) %></th>
    <td><%= f.text_field(:head_size) %></td>
  </tr>
  <tr>
    <th><%= f.label(:racquets_weight) %></th>
    <td><%= f.text_field(:racquets_weight) %></td>
  </tr>
  <tr>
    <th><%= f.label(:category) %></th>
    <td><%= f.text_field(:category) %></td>
  </tr>
  <tr>
    <th><%= f.label(:image_url) %></th>
    <td><%= f.text_field(:image_url) %></td>

  </tr>
</table>