Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.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 我如何推送@host变量,使其在提交表单时工作?_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 我如何推送@host变量,使其在提交表单时工作?

Ruby on rails 我如何推送@host变量,使其在提交表单时工作?,ruby-on-rails,ruby,Ruby On Rails,Ruby,不幸的是,我在新页面上有一个表单,尽管引用@host的所有内容都可以很好地显示,但当我单击“提交”时,视图上的所有内容都会出错,即使它显示得很好 评论中的命名错误#创建显示 C:/Sites/aplication/app/views/reviews/new.html.erb其中第13行 提出: nil:NilClass的未定义方法“title” 提取的源(第13行附近): 1 %> 然后单击submit callcreateaction,rails尝试保存@review这不会发生,在这种情况下

不幸的是,我在新页面上有一个表单,尽管引用
@host
的所有内容都可以很好地显示,但当我单击“提交”时,视图上的所有内容都会出错,即使它显示得很好

评论中的命名错误#创建显示 C:/Sites/aplication/app/views/reviews/new.html.erb其中第13行 提出:

nil:NilClass的未定义方法“title” 提取的源(第13行附近):
1 %>
然后单击submit call
create
action,rails尝试保存
@review
这不会发生,在这种情况下,action render
new
视图
@host
not assignment->crash


那么,我该怎么做才能让@host被推呢 要创建函数吗

发送
参数
@host
变量值
形式上


您不能将
@host
变量传递给另一个actionWell,那么我如何才能准确地执行此操作,以便将@host推送到创建函数?我如何准确地将其作为参数发送?表单:控制器:感谢您的帮助。我觉得自己被卡住了。试试这个表单控制器吧,我对你的情况一无所知,所以它可能不起作用。)它给了我一个错误,指的是这行@host=host.find(params[:host_id]),这意味着params[:host_id]没有发送。我可以试试这个
而不是这个
  def new
    signed_in_checker
    @review = Review.new
    @host = Host.find(params[:id])
  end

  def create
    @review = Review.new(review_params)
    @review.user_id = current_user[:id]
    @review.host_id = @host
    if @review.save
      redirect_to @host
    else
      render 'new'
    end
  end
undefined method `title' for nil:NilClass
Extracted source (around line #13):

<%= f.text_area :text %>   
<br>
<%= "How would you rate " + @host.title + "'s support?" %> 

<%= f.radio_button :support, "1 Star" %>
<%= f.label :support, "1 Star", :value => 1 %>
<%=  hidden_field_tag :host_id, @host.id %>
<%= f.submit "Submit my review for " + @host.title %>
  def create
    @host = Host.find(params[:host_id])
    @review = Review.new(review_params)
    @review.user_id = current_user[:id]
    @review.host_id = @host.id
    if @review.save
      redirect_to @host
    else
      render 'new'
    end
  end