0
votes

i'm having some trouble with this code. Actually is pretty simple, but i can't find the problem. The page was working yesterday, but now throws me an

" SyntaxError in ArticlesController#new"

and

"/home/peyu/workspace/blog01/app/controllers/articles_controller.rb:30: syntax error, unexpected keyword_end, expecting end-of-input"

I think i'm missing an "end" or something, but i can't find it. Here's the code

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

So... any idea where's my mistake? Thank you in advance!

And this is the console output:

Started GET "/articles/new" for 127.0.0.1 at 2015-05-10 06:34:10 -0300 ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" /home/peyu/workspace/blog01/app/controllers/articles_controller.rb:22: warning: else without rescue is useless

SyntaxError (/home/peyu/workspace/blog01/app/controllers/articles_controller.rb:30: syntax error, unexpected keyword_end, expecting end-of-input): app/controllers/articles_controller.rb:30: syntax error, unexpected keyword_end, expecting end-of-input

Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (4.8ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.2ms) Rendered /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) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (31.6ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (0.6ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.4ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb within layouts/javascript (15.3ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb within layouts/javascript (0.4ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.6ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (34.2ms)

Started GET "/articles/new" for 127.0.0.1 at 2015-05-10 06:34:10 -0300 /home/peyu/workspace/blog01/app/controllers/articles_controller.rb:22: warning: else without rescue is useless

SyntaxError (/home/peyu/workspace/blog01/app/controllers/articles_controller.rb:30: syntax error, unexpected keyword_end, expecting end-of-input): app/controllers/articles_controller.rb:30: syntax error, unexpected keyword_end, expecting end-of-input

Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (4.6ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.2ms) Rendered /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) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (21.1ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_markup.html.erb (1.1ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.4ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/console.js.erb within layouts/javascript (15.7ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/main.js.erb within layouts/javascript (0.3ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.4ms) Rendered /home/peyu/.rvm/gems/ruby-2.2.1/gems/web-console-2.1.2/lib/web_console/templates/index.html.erb (31.9ms)

2
Have you made any changes to any code between the time out read working and the time it stopped? - Beartech
Also, in your editor, which line is line #30? - Beartech
there is the last "end" statement . Line 30 is the last line... - Peyu
Are you sure you didn't accidentally save an error before, and now that you've fixed it you haven't saved the document? - Mario
Can you show the web console output from the request up to the error? - Beartech

2 Answers

0
votes

You can validate your Ruby file like so

ruby -c articles_controller.rb

I tried it and it is ok. Can you copy & paste the exact file content from the articles_controller.rb please? And which Ruby version are you using?

0
votes

fyi, the private keyword does not require an end, so the correct indenting should be

private

def article_params
  params.require(:article).permit(:title, :text)
end

other than that, the code looks ok. Did you check the code for the template? (probably something like new.html.erb)?