SlideShare a Scribd company logo
1 of 16
NoMethodError
Monday, June 10, 13
SUBLIMETEXT MULTIPLE
CURSORS
• CMD+left
• Alt+left
• selection
•Copy/Paste
• CMD+d
•Ctrl+CMD+g
Monday, June 10, 13
GIT REFLOG AKA UNDO ANYTHING
SHIT!
Monday, June 10, 13
‘DEBUGGING’ STUFF
WITHOUT DOCS
export BUNDLER_EDITOR=subl
bundle open rails
use Sublime Find in files
Tudi varianta:
git clone ....
Gemfile:
gem :devise, path:‘/home/user/stuff/devise’
Monday, June 10, 13
rake db:create db:migrate db:seed
or use Zeus and don’t care
Monday, June 10, 13
MEMOIZATIONTRICKS
def data
@data ||= begin
data = fetch_data("http://www.com")
JSON.load(data)
rescue Errno::ECONNREFUSED
{ error: 'Connection refused.' }
end
end
###
def data
@data = get_data unless instance_variable_defined?(:@data)
end
def get_data
# ...
rescue
# ...
end
Monday, June 10, 13
rails g model Fart ass:references
rails g model Fart ass:belongs_to
automatically adds index
automatically puts belongs_to into model
class CreateFarts < ActiveRecord::Migration
def change
create_table :farts do |t|
t.references :ass, index: true
t.belongs_to :ass, index: true
t.timestamps
end
end
end
class Fart < ActiveRecord::Base
belongs_to :ass
end
Monday, June 10, 13
RUBY INSTRUCTION
SEQUENCE
Monday, June 10, 13
PRESENT?
def show
@user = User.find(params[:id])
if @user.present?
# ...
end
end
def show
@user = User.find(params[:id])
if @user
# ...
end
end
STOP ABUSING!
Monday, June 10, 13
PRESENCE
"".presence # => nil
"X".presence # => "X"
[].presence # => nil
[1].presence # => [1]
Monday, June 10, 13
ACCEPTS_NESTED_ATTRIBUTES_FOR
bundle open rails
implement custom version in our app
Monday, June 10, 13
ADD METHODS WITH SCOPE
class Fart < ActiveRecord::Base
scope :page, ->(page = 1) { where(page: page) } do
def per(per = 10)
limit(per)
end
end
end
Fart.per(20)
# NoMethodError: undefined method `per'
Fart.page(2).per(20).to_sql
# => "SELECT "farts".* FROM "farts" WHERE "farts"."page" = 2
LIMIT 20"
Kaminari does this: .page(...) adds .per(...)
Monday, June 10, 13
GROUP COUNT
# Useless:
Fart.group(:ass_id).count # => { 1 => 1, 2 => 1 }
# Slow:
Fart.group(:ass_id).count.keys.count # => 2
# Fast + should work for any query:
scope = Fart.group(:ass_id).select("1")
query = "SELECT count(*) AS count_all FROM (#{scope.to_sql}) x"
ActiveRecord::Base.connection.execute(query)["count_all"].to_i # => 2
# Gem: mrbrdo/active_record_group_count
Fart.group(:ass_id).returns_count_sum.count # => 2
# Works with Kaminari
Fart.group(:ass_id).returns_count_sum.page(1).per(10)
Monday, June 10, 13
RAILS 3 ASSIGN_ATTRIBUTES
WITHOUT PROTECTION
PS: use strong_parameters (even in Rails 3), attr_accessible sucks
Fart.new(name: 'lol') # ActiveModel::MassAssignmentSecurity::Error
fart = Fart.new({ name: 'lol' }, without_protection: true)
fart.update_attributes({ name: 'lol' }, without_protection: true)
fart.assign_attributes({ name: 'lol' }, without_protection: true)
be careful
Monday, June 10, 13
RAILS CONSOLE SANDBOX
Monday, June 10, 13
Monday, June 10, 13

More Related Content

What's hot

De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKAdolfo Sanz De Diego
 
Java & Script ─ 清羽
Java & Script ─ 清羽Java & Script ─ 清羽
Java & Script ─ 清羽taobao.com
 
How to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter KriensHow to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter Kriensmfrancis
 
Mac OS X Lion で作る WordPress local 環境
Mac OS X Lion で作る WordPress local 環境Mac OS X Lion で作る WordPress local 環境
Mac OS X Lion で作る WordPress local 環境Yuriko IKEDA
 
PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12Kazuki KOMORI
 
Laporan setting dns
Laporan setting dnsLaporan setting dns
Laporan setting dnsSeptian Adi
 
Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily RoutineMaxim Avanov
 
Noung — Snakes of the Tonle Sap
Noung — Snakes of the Tonle SapNoung — Snakes of the Tonle Sap
Noung — Snakes of the Tonle SapNerd Nite Siem Reap
 
Riki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivosti
Riki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivostiRiki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivosti
Riki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivostiDevelcz
 
Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxParis, France
 
The Australian-The Deal Magazine
The Australian-The Deal MagazineThe Australian-The Deal Magazine
The Australian-The Deal Magazinedrocallaghan
 

What's hot (20)

Cpsh sh
Cpsh shCpsh sh
Cpsh sh
 
De 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWKDe 0 a 100 con Bash Shell Scripting y AWK
De 0 a 100 con Bash Shell Scripting y AWK
 
Java & Script ─ 清羽
Java & Script ─ 清羽Java & Script ─ 清羽
Java & Script ─ 清羽
 
How to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter KriensHow to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter Kriens
 
Mac OS X Lion で作る WordPress local 環境
Mac OS X Lion で作る WordPress local 環境Mac OS X Lion で作る WordPress local 環境
Mac OS X Lion で作る WordPress local 環境
 
PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12PHPerのためのPerl入門@ Kansai.pm#12
PHPerのためのPerl入門@ Kansai.pm#12
 
M.php
M.phpM.php
M.php
 
Laporan setting dns
Laporan setting dnsLaporan setting dns
Laporan setting dns
 
Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily Routine
 
SSLC
SSLCSSLC
SSLC
 
Noung — Snakes of the Tonle Sap
Noung — Snakes of the Tonle SapNoung — Snakes of the Tonle Sap
Noung — Snakes of the Tonle Sap
 
Ruby Robots
Ruby RobotsRuby Robots
Ruby Robots
 
Riki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivosti
Riki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivostiRiki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivosti
Riki Fridrich - Grunt, Gulp a spol. - Automatizáciou k maximalizácii lenivosti
 
Python Menu
Python MenuPython Menu
Python Menu
 
Plone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope RpxPlone Conference 2008 Lightning Talk Static Zope Rpx
Plone Conference 2008 Lightning Talk Static Zope Rpx
 
Git avançado
Git avançadoGit avançado
Git avançado
 
Es6 good parts
Es6 good partsEs6 good parts
Es6 good parts
 
Functional php
Functional phpFunctional php
Functional php
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
The Australian-The Deal Magazine
The Australian-The Deal MagazineThe Australian-The Deal Magazine
The Australian-The Deal Magazine
 

Viewers also liked

Papeleta SPIDO
Papeleta SPIDOPapeleta SPIDO
Papeleta SPIDOPedro Mqw
 
Dilemas da maternidade apresentacao
Dilemas da maternidade apresentacaoDilemas da maternidade apresentacao
Dilemas da maternidade apresentacaoalinefiamenghi
 
BORM mesa de negociación
BORM mesa de negociaciónBORM mesa de negociación
BORM mesa de negociaciónPedro Mqw
 
Minigrid review
Minigrid reviewMinigrid review
Minigrid reviewuprmady
 
Seminars Slidecast and Professional Reflection
Seminars Slidecast and Professional ReflectionSeminars Slidecast and Professional Reflection
Seminars Slidecast and Professional ReflectionSebastiaan Debou
 
TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1
TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1
TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1FANNY JEM WONG MIÑÁN
 
Concept of energy transmission & distribution
Concept of energy transmission & distribution Concept of energy transmission & distribution
Concept of energy transmission & distribution ZunAib Ali
 

Viewers also liked (10)

Resume 97-2003
Resume 97-2003Resume 97-2003
Resume 97-2003
 
Papeleta SPIDO
Papeleta SPIDOPapeleta SPIDO
Papeleta SPIDO
 
Dilemas da maternidade apresentacao
Dilemas da maternidade apresentacaoDilemas da maternidade apresentacao
Dilemas da maternidade apresentacao
 
BORM mesa de negociación
BORM mesa de negociaciónBORM mesa de negociación
BORM mesa de negociación
 
3.meteo vetta dante
3.meteo vetta dante3.meteo vetta dante
3.meteo vetta dante
 
Image180314132650
Image180314132650Image180314132650
Image180314132650
 
Minigrid review
Minigrid reviewMinigrid review
Minigrid review
 
Seminars Slidecast and Professional Reflection
Seminars Slidecast and Professional ReflectionSeminars Slidecast and Professional Reflection
Seminars Slidecast and Professional Reflection
 
TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1
TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1
TEORIAS DE LA PERSONALIDAD- CARACTER Y TEMPERAMENTO-FANNY JEM WONG- SEMANA 1
 
Concept of energy transmission & distribution
Concept of energy transmission & distribution Concept of energy transmission & distribution
Concept of energy transmission & distribution
 

Similar to Nomethoderror talk

Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosEdgar Suarez
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4Jan Berdajs
 
A Better UJS for Rails
A Better UJS for RailsA Better UJS for Rails
A Better UJS for RailsZack Siri
 
Dtrace и немного магии
Dtrace и немного магииDtrace и немного магии
Dtrace и немного магииDan Kruchinin
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...Functional Thursday
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mateCodemotion
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Peter Higgins
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkBen Scofield
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8Allie Jones
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsagniklal
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Slides changes symfony23
Slides changes symfony23Slides changes symfony23
Slides changes symfony23Javier López
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the newRemy Sharp
 
Workflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.jsWorkflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.jsDavidson Fellipe
 

Similar to Nomethoderror talk (20)

Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4D-Talk: What's awesome about Ruby 2.x and Rails 4
D-Talk: What's awesome about Ruby 2.x and Rails 4
 
Migrating legacy data
Migrating legacy dataMigrating legacy data
Migrating legacy data
 
A Better UJS for Rails
A Better UJS for RailsA Better UJS for Rails
A Better UJS for Rails
 
Dtrace и немного магии
Dtrace и немного магииDtrace и немного магии
Dtrace и немного магии
 
[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...[FT-7][snowmantw] How to make a new functional language and make the world be...
[FT-7][snowmantw] How to make a new functional language and make the world be...
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mate
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Trimming The Cruft
Trimming The CruftTrimming The Cruft
Trimming The Cruft
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
Debugging in drupal 8
Debugging in drupal 8Debugging in drupal 8
Debugging in drupal 8
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Slides changes symfony23
Slides changes symfony23Slides changes symfony23
Slides changes symfony23
 
jQuery: out with the old, in with the new
jQuery: out with the old, in with the newjQuery: out with the old, in with the new
jQuery: out with the old, in with the new
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Workflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.jsWorkflow para desenvolvimento Web & Mobile usando grunt.js
Workflow para desenvolvimento Web & Mobile usando grunt.js
 

Recently uploaded

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Nomethoderror talk

  • 2. SUBLIMETEXT MULTIPLE CURSORS • CMD+left • Alt+left • selection •Copy/Paste • CMD+d •Ctrl+CMD+g Monday, June 10, 13
  • 3. GIT REFLOG AKA UNDO ANYTHING SHIT! Monday, June 10, 13
  • 4. ‘DEBUGGING’ STUFF WITHOUT DOCS export BUNDLER_EDITOR=subl bundle open rails use Sublime Find in files Tudi varianta: git clone .... Gemfile: gem :devise, path:‘/home/user/stuff/devise’ Monday, June 10, 13
  • 5. rake db:create db:migrate db:seed or use Zeus and don’t care Monday, June 10, 13
  • 6. MEMOIZATIONTRICKS def data @data ||= begin data = fetch_data("http://www.com") JSON.load(data) rescue Errno::ECONNREFUSED { error: 'Connection refused.' } end end ### def data @data = get_data unless instance_variable_defined?(:@data) end def get_data # ... rescue # ... end Monday, June 10, 13
  • 7. rails g model Fart ass:references rails g model Fart ass:belongs_to automatically adds index automatically puts belongs_to into model class CreateFarts < ActiveRecord::Migration def change create_table :farts do |t| t.references :ass, index: true t.belongs_to :ass, index: true t.timestamps end end end class Fart < ActiveRecord::Base belongs_to :ass end Monday, June 10, 13
  • 9. PRESENT? def show @user = User.find(params[:id]) if @user.present? # ... end end def show @user = User.find(params[:id]) if @user # ... end end STOP ABUSING! Monday, June 10, 13
  • 10. PRESENCE "".presence # => nil "X".presence # => "X" [].presence # => nil [1].presence # => [1] Monday, June 10, 13
  • 11. ACCEPTS_NESTED_ATTRIBUTES_FOR bundle open rails implement custom version in our app Monday, June 10, 13
  • 12. ADD METHODS WITH SCOPE class Fart < ActiveRecord::Base scope :page, ->(page = 1) { where(page: page) } do def per(per = 10) limit(per) end end end Fart.per(20) # NoMethodError: undefined method `per' Fart.page(2).per(20).to_sql # => "SELECT "farts".* FROM "farts" WHERE "farts"."page" = 2 LIMIT 20" Kaminari does this: .page(...) adds .per(...) Monday, June 10, 13
  • 13. GROUP COUNT # Useless: Fart.group(:ass_id).count # => { 1 => 1, 2 => 1 } # Slow: Fart.group(:ass_id).count.keys.count # => 2 # Fast + should work for any query: scope = Fart.group(:ass_id).select("1") query = "SELECT count(*) AS count_all FROM (#{scope.to_sql}) x" ActiveRecord::Base.connection.execute(query)["count_all"].to_i # => 2 # Gem: mrbrdo/active_record_group_count Fart.group(:ass_id).returns_count_sum.count # => 2 # Works with Kaminari Fart.group(:ass_id).returns_count_sum.page(1).per(10) Monday, June 10, 13
  • 14. RAILS 3 ASSIGN_ATTRIBUTES WITHOUT PROTECTION PS: use strong_parameters (even in Rails 3), attr_accessible sucks Fart.new(name: 'lol') # ActiveModel::MassAssignmentSecurity::Error fart = Fart.new({ name: 'lol' }, without_protection: true) fart.update_attributes({ name: 'lol' }, without_protection: true) fart.assign_attributes({ name: 'lol' }, without_protection: true) be careful Monday, June 10, 13