0

Currently i'm using form_for read read a text_field called :comment, after the user submit it goes to the controller as such:

  def create
    @entry = Entry.new(entry_params)
    if @entry.save
      redirect_to :back
    else
      render 'new'
    end
  end

  private

    def entry_params
      params.require(:entry).permit(:comment)
    end

my question is whether I can search inside :comment (string) for a substring "test", when submitting?

Thanks

4

1 回答 1

0

您可以使用 访问评论文本字段中提交的内容params[:entry][:comment],因此您应该能够将其与您想要的值进行比较params[:entry][:comment].include?("test")

于 2013-09-20T04:24:49.257 回答