Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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第一个参数不能包含nil或为空_Ruby_Ruby On Rails 3_Ruby On Rails 4 - Fatal编程技术网

表单中的Ruby on Rails第一个参数不能包含nil或为空

表单中的Ruby on Rails第一个参数不能包含nil或为空,ruby,ruby-on-rails-3,ruby-on-rails-4,Ruby,Ruby On Rails 3,Ruby On Rails 4,我使用了标准的RubyonRails生成脚手架。我需要帮助了解如何将表单从“新建”视图移动到“发布”视图(主页)。我不断得到错误“表单中的第一个参数不能包含nil或为空”。这是我的“帖子”视图代码。它在“新建”视图中工作良好,但在“发布”视图中工作不好 帖子视图: <%= form_for(@post) do |f| %> 新观点: <h1>New post</h1> <%= render 'form' %> <%= link_to

我使用了标准的RubyonRails生成脚手架。我需要帮助了解如何将表单从“新建”视图移动到“发布”视图(主页)。我不断得到错误“表单中的第一个参数不能包含nil或为空”。这是我的“帖子”视图代码。它在“新建”视图中工作良好,但在“发布”视图中工作不好

帖子视图:

<%= form_for(@post) do |f| %>

新观点:

<h1>New post</h1>

<%= render 'form' %>

<%= link_to 'Back', posts_path %>
新职位
表单视图:

<%= form_for(@post) do |f| %>
  <% if @post.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>

      <ul>
      <% @post.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

   </div>
    <div class="field">
    <%= f.label :casino %>
    <%= f.text_field :casino %>
  </div>
     </div>
    <div class="field">
    <%= f.label :City %>
    <%= f.text_field :City %>
  </div>
  </div>
     </div>
    <div class="field">
    <%= f.label :State %>
    <%= f.text_field :State %>
  </div>
       </div>
    <div class="field">
    <%= f.label :Country %>
    <%= f.text_field :Country %>
  </div>
  <div class="field">
    <%= f.label :Game %>
    <%= f.text_field :title %>
  <div class="field">
    <%= f.label :Minimum %>
    <%= f.text_field :text %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

禁止保存此帖子:
控制器代码:

class PostsController < ApplicationController

  before_action :set_post, only: [:show, :edit, :update, :destroy]

  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.all
  end

  # GET /posts/1
  # GET /posts/1.json
  def show
  end

  # GET /posts/new
  def new
    @post = Post.new
  end

  # GET /posts/1/edit
  def edit
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = Post.new(post_params)

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /posts/1
  # PATCH/PUT /posts/1.json
  def update
    respond_to do |format|
      if @post.update(post_params)
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { render :show, status: :ok, location: @post }
      else
        format.html { render :edit }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post.destroy
    respond_to do |format|
      format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_post
      @post = Post.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def post_params
      params.require(:post).permit(:title, :text, :casino, :City, :State, :Country)
    end
end
class PostsController
在PostsController的索引操作中添加此行

@post = Post.new
这将解决您的问题:)

解决方案:

class PostsController
在PostsController的索引操作中添加此行

@post = Post.new
这将解决您的问题:)

解决方案:

class PostsController
在PostsController的索引操作中添加此行

@post = Post.new
这将解决您的问题:)

解决方案:

class PostsController
在PostsController的索引操作中添加此行

@post = Post.new
这将解决您的问题:)

解决方案:

class PostsController
您的
帖子视图的文件名是什么
?您的
帖子视图的文件名是什么
?您的
帖子视图的文件名是什么
?非常感谢!成功了。我周五晚上在酒吧花了5个小时想弄明白,而你本周又为我节省了5个小时。我将发布解决方案。现在我想我已经掌握了控制器以及它们的操作方式。下一步是找出一个动态搜索,我可以添加到主页。非常感谢!成功了。我周五晚上在酒吧花了5个小时想弄明白,而你本周又为我节省了5个小时。我将发布解决方案。现在我想我已经掌握了控制器以及它们的操作方式。下一步是找出一个动态搜索,我可以添加到主页。非常感谢!成功了。我周五晚上在酒吧花了5个小时想弄明白,而你本周又为我节省了5个小时。我将发布解决方案。现在我想我已经掌握了控制器以及它们的操作方式。下一步是找出一个动态搜索,我可以添加到主页。非常感谢!成功了。我周五晚上在酒吧花了5个小时想弄明白,而你本周又为我节省了5个小时。我将发布解决方案。现在我想我已经掌握了控制器以及它们的操作方式。下一步是找出可以添加到主页的dynamics搜索。