Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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 下面第5条字母在ruby上不保存时是保存的_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 下面第5条字母在ruby上不保存时是保存的

Ruby on rails 下面第5条字母在ruby上不保存时是保存的,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我正在关注RubyonRails文档,如果我的标题是下面5个字母,我的标题就不会保存,但我的标题正在保存。 有人能告诉我我出了什么问题,以及我如何解决它吗 这是我的文章 class Article < ApplicationRecord validates :title, presence: true, length: { minimum: 5 } end 类文章

我正在关注RubyonRails文档,如果我的标题是下面5个字母,我的标题就不会保存,但我的标题正在保存。 有人能告诉我我出了什么问题,以及我如何解决它吗

这是我的文章

class Article < ApplicationRecord
 validates :title, presence: true,
                    length: { minimum: 5 }
end
类文章
我的文章\u controller.rb

class ArticlesController < ApplicationController
    def index
      @articles = Article.all
    end

    def show
      @article = Article.find(params[:id])
    end


def new
  @article = Article.new
end

def create
  @article = Article.new(article_params)

  if @article.save
    redirect_to @article
  else
    render 'new'
  end
end

private
  def article_params
    params.require(:article).permit(:title, :text)
  end
 end
class-ArticlesController
还有我的new.html.erb

<%= form_with scope: :article, url: articles_path, local: true do |form| %>

  <% if @article.errors.any? %>
    <div id="error_explanation">
      <h2>
        <%= pluralize(@article.errors.count, "error") %> prohibited
        this article from being saved:
      </h2>
      <ul>
        <% @article.errors.full_messages.each do |msg| %>
          <li><%= msg %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <p>
    <%= form.label :title %><br>
    <%= form.text_field :title %>
  </p>

  <p>
    <%= form.label :text %><br>
    <%= form.text_area :text %>
  </p>

  <p>
    <%= form.submit %>
  </p>

<% end %>

<%= link_to 'Back', articles_path %>

禁止
要保存此文章,请执行以下操作:


作为初学者,文档是学习ruby的好方法吗?或者推荐任何教程视频

类文章class Article < ApplicationRecord
 validates :title, presence: true
 validates_length_of :title, :minimum => 5
end
验证:标题,状态:true 验证以下内容的长度:title,:minimum=>5 结束

请检查日志并在注释中粘贴保存标题时传递的标题参数值好吗?@OmiyeraDamilola如果对您有帮助,请随时接受/upvote答案。