Hello i think i'm blind and i don't find the bug in the syntax
def update
#list = List.find_by(key: params[:id])
if (check_email_link(params[:expdate] && #list.update(wishlist_params))
flash[:notice] = t("update")
redirect_to (admin_list_url)
else
flash[:error] = t("not_active")
render 'edit'
end
end
The expdate contains a datetimestamp and the check_email_link is a method that checks the date and time of a link in the mail
There are three syntax errors
app/controllers/admin/lists_controller.rb:32: syntax error, unexpected keyword_else, expecting ')'
app/controllers/admin/lists_controller.rb:35: syntax error, unexpected keyword_end, expecting ')'
app/controllers/admin/lists_controller.rb:86: syntax error, unexpected keyword_end, expecting ')'
I'm an idiot or i'm blind. Can someone help an explain me the error? Thanks
(check_email_link(params[:expdate] && #list.update(wishlist_params)) has three (s and two )s. You need either another ) or one less (. I can't be sure where, as I don't know your code.
While we're on it, the if line shouldn't be indented the extra level, as it kinda makes it look like the line above starts a block.
Related
The following is a json.jbuildermethod intended to respond to an API call.
if #error_code_98?
json.set! :chain_category do
json.set! :error, #error_98_messages
end
end
#error_code_99 = true when said errors arise.
error_98_messages is a concatenation of string that provide an indentifier with the nature of the error. They are accumulated as an array of items are handled by the API action.
When the error hits, the instance variable gets populated, but at the end of the action the return message this the following error
syntax error, unexpected tSYMBEG, expecting ':'
json.set! :chain_category do
I thought this was respecting the syntax for dynamic attribution, but that is mistaken. Where is the syntax off?
I'm getting this syntax error and I don't know what I'm supposed to do and I'm new to Ruby. In the future could someone tell me how I can resolve syntax errors
SyntaxError (/Users/admin/Moralyzer/app/controllers/petition_posts_controller.rb:23: syntax error, unexpected tLABEL, expecting ')'
url: item['url'],
^~~~
/Users/admin/Moralyzer/app/controllers/petition_posts_controller.rb:24: syntax error, unexpected tLABEL, expecting '='
media_type: item['type']
^~~~~~~~~~~
/Users/admin/Moralyzer/app/controllers/petition_posts_controller.rb:25: syntax error, unexpected ')', expecting end
)
^
/Users/admin/Moralyzer/app/controllers/petition_posts_controller.rb:28: syntax error, unexpected else, expecting end
else
^~~~
/Users/admin/Moralyzer/app/controllers/petition_posts_controller.rb:58: syntax error, unexpected end-of-input, expecting end):
app/controllers/petition_posts_controller.rb:23: syntax error, unexpected tLABEL, expecting ')'
app/controllers/petition_posts_controller.rb:24: syntax error, unexpected tLABEL, expecting '='
app/controllers/petition_posts_controller.rb:25: syntax error, unexpected ')', expecting end
app/controllers/petition_posts_controller.rb:28: syntax error, unexpected else, expecting end
app/controllers/petition_posts_controller.rb:58: syntax error, unexpected end-of-input, expecting end
The code
# POST /petition_posts
def create
#petition_posts = PetitionPost.new(petition_posts_params)
if #petition_posts.save
for item in media
#petition_posts.media.create (
url: item['url'],
media_type: item['type']
)
end
render json: #petition_posts, status: :created, location: #petition_posts
else
render json: #petition_posts.errors, status: :unprocessable_entity
end
end
Ruby doesn't want white-space between method name and the opening parentheses
#petition_posts.media.create (
should be
#petition_posts.media.create(
As a bonus point for loops are not the Ruby way, use each instead
media.each do |item|
#petition_posts.media.create(url: item['url'], media_type: item['type'])
end
Try changing this:
#petition_posts.media.create (
url: item['url'],
media_type: item['type']
)
To this:
#petition_posts.media.create(url:item['url'], media_type:item['type'])
All in one line.
Edit: I don't mean to edit so much in one minute (I'm kind of new to stackoverflow) but I figured out the issue. It isn't whitespace but where you put the terminating ')' for that function.
So the following are all valid:
#petition_posts.media.create(url:item['url'],
media_type:item['type'])
#petition_posts.media.create(
url:item['url'],
media_type:item['type'])
#petition_posts.media.create(
url:item['url'], media_type:item['type'])
As long as the ')' is attached to the end of your arguments list, you should be good.
I am trying to use where.not to replace the following:
if #friend_matches.count > 0
#court_matches = Match.available_on_courts.where('matches.id NOT IN (?)', #friend_matches.pluck(:id)).to_a
else
#court_matches = Match.available_on_courts
end
With
#court_matches = Match.available_on_courts.where.not(matches.id: #friend_matches.pluck(:id)).to_a
However I am getting the following errors.
SyntaxError: /Users/sripaladugu/Coding/matchpoint_rails/app/mailers/match_mailer.rb:8: syntax error, unexpected ':'
...on_courts.where.not(matches.id: #friend_matches.pluck(:id))....
... ^
/Users/sripaladugu/Coding/matchpoint_rails/app/mailers/match_mailer.rb:8: syntax error, unexpected ')', expecting keyword_end
...id: #friend_matches.pluck(:id)).to_a
You can provide a hash within where to specify table names as keys and column names within the second level:
#court_matches = Match.available_on_courts
.where.not(matches: { id: #friend_matches.pluck(:id) })
.to_a
Basically, CSV import doesn't work.
Model Code:
def self.import(file,admin_id)
spreadsheet = open_spreadsheet(file)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = Hash[[header, spreadsheet.row(i)].transpose]
new_row = row.to_hash.merge(:merchant_id => admin_id)
Inventory.create! new_row
end
end
def self.open_spreadsheet(file)
require 'iconv'
case File.extname(file.original_filename)
when ".csv" then Roo::Csv.new(file.path, nil, :ignore)
when ".xls" then Roo::Excel.new(file.path, nil, :ignore)
when ".xlsx" then Roo::Excelx.new(file.path, nil, :ignore)
else raise "Unknown file type: #{file.original_filename}"
end
end
Controller action:
def import
Inventory.import(params[:file],params[:admin_id])
redirect_to :inventories, :notice => "Imported Successfully."
end
Import button, select file, all that working fine. On submit:
SyntaxError in InventoriesController#import
(eval):2: syntax error, unexpected tIDENTIFIER, expecting ')'
read_key(:Parts name)
^
(eval):6: syntax error, unexpected tIDENTIFIER, expecting ')'
read_key_before_type_cast(:Parts name)
^
(eval):10: syntax error, unexpected tIDENTIFIER, expecting ')'
write_key(:Parts name, value)
^
(eval):10: syntax error, unexpected ')', expecting '='
(eval):14: syntax error, unexpected tIDENTIFIER, expecting ')'
read_key(:Parts name).present?
^
(eval):15: syntax error, unexpected $end, expecting keyword_end
Can someone please shed some light on this? I can't even find a good way to debug the actual method to see exactly what it tries to do and how it fails on.
There is a template CSV file that looks like this across the header row:
Parts name Parts
number Quantity Cost Price Tax Location Description Is editable
Per my comment, the syntax errors arise from trying to turn the column names into symbols, which doesn't work if the column names contain spaces. The offending code appears to be in https://github.com/jnunemaker/mongomapper/blob/f5f695215effea909df65304898f4512600baa08/lib/mongo_mapper/plugins/keys.rb, but I didn't check to see if there is documentation or an issue relating to this.
The answer turned out to be the spaces in the header names. I wish Peter would submit the answer so I can click it
Anyone know why I get a syntax error when I try to use curly braces block syntax for Rails.cache.fetch
This errors out with error (syntax error, unexpected '{', expecting keyword_end (SyntaxError) )
Rails.cache.fetch "person/#{id}" { find(id) }
The following works:
Rails.cache.fetch "person/#{id}" do
find(id)
end
This is because {} has different precedence than do end. In the first expression they are tied to the "person/#{id}" part of the expression.
So your first example is similar to:
Rails.cache.fetch("person/#{id}" { find(id) })
while the second is:
Rails.cache.fetch("person/#{id}") { find(id) }
the short block needs () before to recognise the syntax it should look something like
Rails.cache.fetch("person/#{id}") { find(id) }