Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Odd Syntax Error

syntax error

  • Please log in to reply
2 replies to this topic

#1 amyers

amyers

    Passenger

  • Members
  • 4 posts

Posted 14 February 2014 - 01:17 AM

I'm getting a syntax error for a controller file of mine. When I try to access the contact page of my practice app, on localhost. This is from my error log:  

Processing by ContactsController#new as HTML
Completed 500 Internal Server Error in 2ms

SyntaxError - /Users/NormalUse/ror/learn-rails/app/models/contact.rb:1: syntax error, unexpected ':', expecting ';' or '\n'

Line four in particular is:

@contact = Contact.new

And the full file is:

class ContactsController < ApplicationController

def new
@contact = Contact.new
end

def create
@contact = Contact.new(secure_params)
 if @contact.valid?
# TODO save data
# TODO send message
flash[:notice] = "Message sent from #{@contact.name}." 
redirect_to root_path
else
render :new
end 

end
private
def secure_params
params.require(:contact).permit(:name, :email, :content)
end 

end

It's saying there is an unexpected colon in line four? I don't get it. I've searched and searched for similar problems, but I'm not seeing anything.

I hope somebody can help me out?

 

Thanks!



#2 Bharat Soni

Bharat Soni

    Dispatcher

  • Members
  • 53 posts
  • LocationAhmedabad

Posted 14 February 2014 - 05:49 AM   Best Answer

It seems to occurs because some where  in your /app/model/contact.rb you have used some thing wrong.

 

Please share you model contact.rb here. 


  • james likes this

Fun with Ruby on Rails


#3 amyers

amyers

    Passenger

  • Members
  • 4 posts

Posted 15 February 2014 - 07:11 PM

Ugh! Yes that was it! There was an extra space in a spot within my contact.rb file. Thank you very much!







Also tagged with one or more of these keywords: syntax, error

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users