我在使用此代码时遇到了一些问题。其实很简单,但我找不到问题。该页面昨天正在运行,但现在却抛出了一个
" ArticlesController#new"中的SyntaxError;
和
" /home/peyu/workspace/blog01/app/controllers/articles_controller.rb:30:语法错误,意外的keyword_end,期待输入结束"
我想我错过了一个"结束"什么的,但我无法找到它。这是代码
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
那么......任何想法都是我的错误?提前谢谢!
这是控制台输出:
开始GET&#34; / articles / new&#34;在2015-05-10 06:34:10 -0300为127.0.0.1 ActiveRecord :: SchemaMigration Load(0.1ms)SELECT&#34; schema_migrations&#34;。* FROM&#34; schema_migrations&#34; /home/peyu/workspace/blog01/app/controllers/articles_controller.rb:22:警告:没有救援的其他东西是没用的
SyntaxError(/home/peyu/workspace/blog01/app/controllers/articles_controller.rb:30:语法错误,意外的keyword_end,期望输入结束): app / controllers / articles_controller.rb:30:语法错误,意外的keyword_end,期待输入结束
呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb(4.8ms) 呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb(2.2ms) 呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb(10.6ms) 在救援/布局(31.6ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb 已呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb(0.6ms) 在layouts / inlined_string(0.4ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb 在layouts / inlined_string(0.3ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb 在layouts / inlined_string(0.3ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb 在layouts / javascript(15.3ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb 在layouts / javascript(0.4ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb 在layouts / javascript(0.6ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb 已呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb(34.2ms)
开始GET&#34; / articles / new&#34;在2015-05-10 06:34:10 -0300为127.0.0.1 /home/peyu/workspace/blog01/app/controllers/articles_controller.rb:22:警告:没有救援的其他东西是没用的
SyntaxError(/home/peyu/workspace/blog01/app/controllers/articles_controller.rb:30:语法错误,意外的keyword_end,期望输入结束): app / controllers / articles_controller.rb:30:语法错误,意外的keyword_end,期待输入结束
呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb(4.6ms) 呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb(2.2ms) 呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb(1.4ms) 在救援/布局(21.1ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb 已呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb(1.1ms) 在layouts / inlined_string(0.4ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb 在layouts / inlined_string(0.3ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb 在layouts / inlined_string(0.3ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb 在layouts / javascript(15.7ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb 在layouts / javascript(0.3ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb 在layouts / javascript(0.4ms)内呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb 已呈现/home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb(31.9ms)
答案 0 :(得分:0)
您可以像这样验证您的Ruby文件
ruby -c articles_controller.rb
我试过了,没关系。你能复制一下吗?请粘贴articles_controller.rb中的确切文件内容吗?你使用的是哪个Ruby版本?
答案 1 :(得分:0)
fyi,private
关键字不需要结束,因此正确的缩进应该是
private
def article_params
params.require(:article).permit(:title, :text)
end
除此之外,代码看起来还不错。你检查了模板的代码吗? (可能类似于new.html.erb)?