syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) - laravel-5.1

I am using laravel5.0 on centos 6.9, when I try to run php artisan migarate , getting error PHP Parse error:
syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /root/.local/share/Trash/files/keystone_laravel.2/laravel/artisan on line 3
please anyone help

Change the version of your php for L5.0 you need to install a
PHP >= 5.4, PHP < 7
https://laravel.com/docs/5.0

I'm using Laravel5.4 and CentOS7.4, and PHP5.4 pre-installed into the system, but I installed php7.0 manually by source-code without link it to /usr/bin so when I run php artisan schedule:run, it actually run the command with php5.4, and of course I get the same error. So I link php7.0 to /usr/bin to make it as default php, then I fixed it.

Related

How to configure Atom linter-rubocop to run --rails flag always

I'm getting conflicting cops between my IDE and the console. How do I have Atom's linter-rubocop to always run with the --rails flag?
Error in Atom:
Error in console:
This is my config.cson:
...
"linter-rubocop":
command: "rubocop -R"
The settings-page for linter-rubocop describes that the command-option should be provided with an absolute path. That is, the output of which rubocop. Then you can add the parameter.

Syntax error while executing any brew command

Error:
/usr/local/bin/brew: line 1: syntax error near unexpected token '<<<'
/usr/local/bin/brew: line 1: '<<<<<<< 61ffa47gd9dc179ddff792db1dc6f55464f6c16b'
I tried removing and adding closing triangular brackets but neither one worked for me.
I found some similar questions/answers related to this where unexpected token was ')', but they didn't help.
This is an unresolved git conflict. Run the following command and you’ll be fine:
cd /usr/local && git fetch && git reset --hard origin/master
Seems to be similar issue than Homebrew on Mac OS X (El Capitan): syntax error near unexpected token `{
dos2unix /usr/local/bin/brew

Deploy hook syntax error

Trying to give permissions to /public/uploads with deploy hook, during cloud66 deploy to digitalocean, to get carrierwave file uploads working.
I'm receiving the following error:
Error during deployment: Error during after_rails hook: Execution of sudo
/tmp/open_folder_permissions.sh returned a non-zero exit code. Output was:
/tmp/open_folder_permissions.sh:5: syntax error, unexpected tGVAR, expecting keyword_do or
'{' or '(' sudo chmod 0775 -R $RAILS_STACK_PATH/public/uploads ^
open_folder_permissions.sh
#! /usr/bin/env ruby
#load environment variables
source /var/.cloud66_env
#assign desired permissions
sudo chmod 0775 -R $RAILS_STACK_PATH/public/uploads
deploy_hooks.yml
production:
after_rails:
- source: /.cloud66/files/open_folder_permissions.sh
destination: /tmp/open_folder_permissions.sh
target: rails
execute: true
run_on: all_servers
apply_during: all
sudo: true
What could cause the error?
Your open_folder_permissions.sh doesn't contain valid Ruby code. From the looks of it, it's supposed to be a shell script, not a Ruby script, so you should change the shebang line to a shell interpreter instead of a Ruby interpreter.
#! bin/bash is the right interpreter.

check syntax of ruby/jruby script using jruby -c syntax check (inside ruby code)

I am in a search of some way , using which in ruby code I should be able to create a temp file and then append some ruby code in that, then pass that temp file path to jruby -c to check for any syntax errors.
Currently I am trying the following approach:
script_file = File.new("#{Rails.root}/test.rb", "w+")
script_file.print(content)
script_file.close
command = "#{RUBY_PATH} -c #{Rails.root}/test.rb"
eval(command);
new_script_file.close
When I inspect command var, it is properly showing jruby -c {ruby file path}. But when I execute the above piece of code I am getting the following error:
Completed 500 Internal Server Error in 41ms
SyntaxError ((eval):1: dhunknown regexp options - dh):
Let me know if any one has any idea on this.
Thanks,
Dean
eval evaluates the string as Ruby code, not as a command line invocation:
Since your command is not valid Ruby syntax, you get this exception.
If you want to launch a command in Ruby, you can use %x{} or ``:
output1 = ls
output2 = %x{ls}
Both forms will return the output of the launched command as a String, if you want to process it. If you want this output to be directly displayed in the user terminal, you can use system():
system("ls")

Post XML to an external API - Using cURL in Rails

I've been working in the Rails console with Rails 3.2 and I'm generating an XML file using Nokogiri. From here, I need to post to an external API to grab some data and return it within my app. Eventually this code will be a function of the controller, but for now I've been experimenting in the console.
I generated and XML file with Nokogiri and parameters I specified, and I stored the output using the following command:
File.open('results.xml', 'w') {|f| f.write(results)}
From here, I want to POST this file to the external API. The command I used saved it in the /public directory of my app. From here, I'm unsure of how to access it with cURL.
I tried putting it in a views directory and set up a route so I can GET the file, and I can at least access it. Here is what I tried in cURL (note that the Rails server was running at the time and the API path below is made up for example purposes):
curl -X POST -v --data-ascii http://localhost:3000/search/postresults.xml http://APIPATH/example.php
This one has been frustrating me for awhile, and when I try that I get an error saying:
SyntaxError: (irb):5: syntax error, unexpected tCONSTANT, expecting keyword_do or '{' or '('
curl -X POST -v --data-ascii http://local...
^
(irb):5: syntax error, unexpected tUMINUS, expecting keyword_do or '{' or '('
curl -X POST -v --data-ascii http://localhost:...
^
(irb):5: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
...l
-X POST -v --data-ascii http://localhost:3000/search/postr...
... ^
(irb):5: unknown regexp options - lcalht
I've tried all of the standard troubleshooting (curl is installed - version 0.0.9, server is running, curl is in my Gemfile, etc), so any help is much appreciated. Thanks!
Your errors suggest that you typed the curl command and arguments directly into IRb. That's not how Ruby gems work. Furthermore, if you want to POST to an HTTP resource from Rails don't bother with cURL. Rails has built-in tools for this.
If you're going to be interacting with this API a lot, and if the API is fairly RESTy, then take a look at ActiveResource (tutorials abound on Google if the docs don't do it for you).
If you're not using a very RESTy API, or if this is a one-off API call, you can create an instance of ActiveResource::Connection directly, e.g.:
conn = ActiveResource::Connection.new 'http://example.com'
result = conn.post 'example.php', results
There's likely no need to write the Nokogiri document (results) to a file, just give it directly to ActiveResource::Connection#post.

Resources