I am having compile errors. Could you guys help me get aroudn it. This in my view (the third line with 5prime_primer in particular):
<tr>
<td><%=relation.AmpInfoName%></td>
<td><%=relation.5prime_primer%></td>
<td><%=relation.3prime_primer%></td>
<td><%=relation.Selective_bases_1%></td>
<td><%=relation.Selective_bases_2%></td>
</tr>
Produces this error:
compile error
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:314: no .<digit> floating literal anymore; put 0 before dot
...tput_buffer.append= (relation.5prime_primer);#output_buffer....
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:314: syntax error, unexpected tINTEGER
...put_buffer.append= (relation.5prime_primer);#output_buffer.s...
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:315: no .<digit> floating literal anymore; put 0 before dot
...tput_buffer.append= (relation.3prime_primer);#output_buffer....
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:315: syntax error, unexpected tINTEGER
...put_buffer.append= (relation.3prime_primer);#output_buffer.s...
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:338: no .<digit> floating literal anymore; put 0 before dot
...tput_buffer.append= (relation.5prime_primer);#output_buffer....
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:338: syntax error, unexpected tINTEGER
...put_buffer.append= (relation.5prime_primer);#output_buffer.s...
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:339: no .<digit> floating literal anymore; put 0 before dot
...tput_buffer.append= (relation.3prime_primer);#output_buffer....
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:339: syntax error, unexpected tINTEGER
...put_buffer.append= (relation.3prime_primer);#output_buffer.s...
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:354: no .<digit> floating literal anymore; put 0 before dot
...tput_buffer.append= (relation.5prime_primer);#output_buffer....
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:354: syntax error, unexpected tINTEGER
...put_buffer.append= (relation.5prime_primer);#output_buffer.s...
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:355: no .<digit> floating literal anymore; put 0 before dot
...tput_buffer.append= (relation.3prime_primer);#output_buffer....
^
/usr/home/benjamin/locus/app/views/locus_table/show.html.erb:355: syntax error, unexpected tINTEGER
...put_buffer.append= (relation.3prime_primer);#output_buffer.s...
Could you guys help me figure out how to get around this?
Ruby method names can't start with numbers. You can however define you own accessors:
class Foo < ActiveRecord::Base
def three_prime_primer
read_attribute '3_prime_primer'
end
def three_prime_primer=(value)
write_attribute '3_prime_primer', value
end
end
It wouldn't be hard to wrap this up in a little method so that you could do
access_attribute '3_prime_primer', :as => 'three_prime_primer'
I defined a method in my model and then looked up the attribute using a hashmap:
class AmplificationInfoTable < ActiveRecord::Base
attr_accessor :all
def fiveprime_primer
attributes["5prime_primer"]
end
end
This allowed me to do things such as:
relation.fiveprime_primer
Peace!
Related
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 define a scope whereby a field in a related object has a value of 1. It seems to throw an error when I do this:
scope :in_progress, ->{Submission.where(current_agent.agent_activities.last.Status: 1)}
Desired effect is to call all Submissions that have a status of "In progress" which has a hash value of 1.
Error:
SyntaxError (/Users/gbade/Desktop/RoR/Ottom8/app/models/submission.rb:16: syntax error, unexpected ':'
.agent_activities.last.Status: 1)}
^):
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.
Trying to write an RSpec test that checks a function location_counts(piece) that returns a hash table with some keys and values assigned.
describe "location_counts(piece)" do
it "should return a hash table with a key of locations and value of times visited" do
game = FactoryGirl.create(:game)
black_queen = FactoryGirl.create(:queen, game_id: game.id, row: 8, column: 4, is_black: true)
black_queen.move_to(4,4)
black_queen.move_to(1,1)
black_queen.move_to(4,4)
expect(game.location_counts(black_queen)).to be {"4, 4"=>2, "1, 1"=>1}
end
end
With this test, I'm getting a syntax error.
That looks like:
/usr/local/rvm/gems/ruby-2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/configuration.rb:1435:in `load': /home/ubuntu/workspace/chess-app/spec/models/game_spec.rb:101: syntax error, unexpected =>, expecting '}' (SyntaxError)
...s(black_queen)).to be {"4, 4"=>2, "1, 1"=>1}
... ^
/home/ubuntu/workspace/chess-app/spec/models/game_spec.rb:101: syntax error, unexpected =>, expecting '}'
...en)).to be {"4, 4"=>2, "1, 1"=>1}
... ^
The problem seems to be that ruby is interpreting your expected hash:
expect(game.location_counts(black_queen)).to be {"4, 4"=>2, "1, 1"=>1}
as a block passed to the be method, instead of as a parameter. Try the following:
expect(game.location_counts(black_queen)).to eq({"4, 4"=>2, "1, 1"=>1})
or even removing the curly braces, as the hash is the last parameter passed to the be method:
expect(game.location_counts(black_queen)).to eq("4, 4"=>2, "1, 1"=>1)
EDIT: Regard the usage of eq instead of be.
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