Home > rails syntax > rails syntax error reserved word function

Rails Syntax Error Reserved Word Function

Contents

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this convert js to coffee site About Us Learn more about Stack Overflow the company Business Learn javascript in rails more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question coffeescript function x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ExecJS::ProgramError: coffeescript tutorial SyntaxError: Reserved word “function” up vote 28 down vote favorite 1 In our rails rfq.js.coffee, we only have a simple js code: $(function() { $('#need_report').change(function(){ if ($(this).val() == true) { $('#report_language').hide(); } // end if }); // end change() }); // end ready(function) However this code causes an error saying that function() in first line is a reserved word. Since the first line is

Coffee Script

basically a jquery $(document).ready(function () {}), we have no clue why this error shows up. Any thoughts about it? Thanks so much. javascript jquery ruby-on-rails coffeescript share|improve this question edited Jan 25 '12 at 22:15 Dylan Markow 91.2k16225174 asked Jan 25 '12 at 22:08 user938363 1,762114796 2 Wait, is this CoffeeScript? Why are you using normal JS in CoffeeScript? –Blender Jan 25 '12 at 22:11 6 js2coffee.org will be your friend –Jesse Wolgamott Jan 25 '12 at 22:21 add a comment| 2 Answers 2 active oldest votes up vote 40 down vote accepted You can't use standard JS like that in a Coffeescript file. Either rename the file to rfq.js, or convert it to coffeescript: $ -> $('#need_report').change -> if $(this).val() $('#report_language').hide() share|improve this answer edited Jan 25 '12 at 22:16 Domenic 61.5k22158225 answered Jan 25 '12 at 22:14 Dylan Markow 91.2k16225174 3 Just renamed the file to js file. Thought js can be used in coffee script without any change. Also found a site to convert the js to coffee script or vise verse. js2coffee.org thanks. –user938363 Jan 25 '12 at 23:03 Yeah

here for a quick overview of the site Help Center Detailed answers to any questions you might have

Coffeescript Vs Javascript

Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, http://stackoverflow.com/questions/9011103/execjsprogramerror-syntaxerror-reserved-word-function just like you, helping each other. Join them; it only takes a minute: Sign up Ruby on Rails js is broken up vote 0 down vote favorite 1 I've recently gotten back into Ruby and its finally working for me. That is, until I try to include js. This error shows up all the time, and http://stackoverflow.com/questions/33375754/ruby-on-rails-js-is-broken at first deleting the line mentioned worked Showing C:/Users/1/2/app/views/layouts/application.html.erb where line #6 raised: SyntaxError: [stdin]:1:18: reserved word "function" Rails.root: C:/Users/1/2 But that doesn't fix the issue, and I need to use javascript in my project. I've tried changing <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> to <%= javascript_include_tag 'default', 'data-turbolinks-track' => true %> but then javascript doesn't work I've tried installing node, and node works. Javascript still doesn't. I've tried messing with my runtimes.rb JScript = ExternalRuntime.new( :name => "JScript", :command => "cscript //E:jscript //Nologo", :runner_path => ExecJS.root + "/support/jscript_runner.js", :encoding => 'UTF-8' # CScript with //U returns UTF-16LE ) I've tried gem 'coffee-script-source', '1.8.0' gem 'therubyracer', platforms: :ruby And still nothing I was really hoping nodejs would help but it didn't. Application.js: // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or any plugin's vendor/assets/javascripts directory can be referenced here using a re

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business http://stackoverflow.com/questions/39378891/getting-reserved-word-function-when-trying-to-define-coffee-script-function Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting “reserved word 'function’” when trying to define coffee script function up vote 0 down vote favorite I have this coffee script @open_login_dialog = rails syntax () -> opt = { autoOpen: false, modal: true, width: 'auto', focus: function(e) -> $(this).dialog('option', 'width', $("#loginBox").width()) } Rails is reporting the cryptic error, “SyntaxError: [stdin]:184:12: reserved word 'function’”. It doesn’t tell me a line, but when I comment out the “focus:function” part everything works, which leads me to believe that’s the culprit. How do I write the above so that it plays nicely with coffee script? function coffeescript focus share|improve this question asked Sep rails syntax error 7 at 20:58 Dave 1 1 You have the right syntax just above where you define @open_login_dialog. –mu is too short Sep 7 at 21:31 Still not working. I changed the line beginning with "focus:" to "focus = (e) ->" and got the error "SyntaxError: [stdin]:184:11: unexpected =". –Dave Sep 8 at 13:49 Well, the error says it all. You need to use : for assignment inside an object, while = is assignment to a variable. What @muistooshort meant is that you should use () -> instead of function. So the line should read focus: (e) -> –Caffeinated.tech Sep 8 at 15:34 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted As per @muistooshort's comment, You need to use coffeescript function syntax, which replaces function(a,b,c) with (a,b,c) -> Secondly, you need to continue using : for assignment inside an object. I would also suggest brushing up a little on coffeescript. This is my favourite resource on the language. A linter would also help to catch these basic syntax errors. Your code can be further cleaned up: @open_login_dialog = -> opt = autoOpen: false modal: true width: 'auto' focus: -> $(this).dialog 'option', 'width', $('#loginBox').width() Explanation If you don't expect any parameters, you can leave out the () from the function definition and jus

 

Related content

rails syntax error unexpected $end expecting kend

Rails Syntax Error Unexpected end Expecting Kend p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies relatedl of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Unexpected end expecting kEND

rails syntax error unexpected kend expecting $end

Rails Syntax Error Unexpected Kend Expecting end p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow relatedl the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Ruby unexpected kEND expecting

rails syntax error unexpected kend

Rails Syntax Error Unexpected Kend p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss relatedl the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up About Ruby error 'kEnd' up vote

rails syntax error unexpected tassoc expecting kend

Rails Syntax Error Unexpected Tassoc Expecting Kend p here for a quick overview of the site Help Center Detailed answers to any questions relatedl you might have Meta Discuss the workings and policies ruby tassoc of this site About Us Learn more about Stack Overflow the company ruby hash Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up

rails syntax error unexpected tassoc

Rails Syntax Error Unexpected Tassoc p here for a quick overview of the site Help relatedl Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Syntax error unexpected tASSOC expecting keyword