我試圖讓Rails中一個字計數器,文字是一種腳手架的名字,但我 @counter變量似乎並沒有被賦予任何輸出如何解決這個@counter沒有給出輸出 - Rails的
class TextsController < ApplicationController
before_action :set_text, only: [:show, :edit, :update, :destroy]
def index
@texts = Text.all
end
def new
@text = Text.new
end
def edit
end
def create
@text = Text.new(text_params)
@counter = @text.name.split.size
end
private
def set_text
@text = Text.find(params[:id])
end
def text_params
params.require(:text).permit(:name, :string)
end
端
VIEW
<p id="notice"><%= notice %></p>
<%= @text.name %>
<%= @counter %>
什麼在'@ text.name'? –
應該算作課本的文本 –
我的意思是,當你在櫃檯裏什麼都沒有時。它是什麼? –