/
index.html
146 lines (107 loc) · 8.41 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE HTML>
<html>
<head>
<title>Home - Blog of Ryan Bigg</title>
<link href="http://feeds.feedburner.com/ryanbigg" rel="alternate" title="The Life of a Radar" type="application/atom+xml" />
<link rel='stylesheet' href='/css/style.css' media='screen'>
<link rel='stylesheet' href='/css/mobile.css'>
<body>
<h1 align='center'>The Life of a Radar</h1>
<div id='page'>
<div id="header">
<p>Hi there, my parents and friends call me Ryan Bigg, but you may know me as "Radar". Either is fine.</p>
<p>I'm a technical writer for Ruby / Rails based in Australia. I have written a Rails book with <a href="http://yehudakatz.com">Yehuda Katz</a> called <a href="http://manning.com/bigg2">Rails 4 in Action</a>, which is available also on <a href='http://www.amazon.com/Rails-3-Action-Ryan-Bigg/dp/1935182277'>Amazon</a>. I'm in the process of writing my second book, <a href='http://leanpub.com/multi-tenancy-rails'>Multitenancy With Rails</a>.
</p>
<div id="more">
<p>
I won a <a href='http://rubyheroes.com'>Ruby Hero</a> award in 2011 for my work on documentation for Rails. I keep some guides in my <a href='http://github.com/radar/guides'>guides</a> repository on GitHub. As part of this documentation, I've worked on the <a href='http://guides.rubyonrails.org/asset_pipeline.html'>Asset Pipeline</a>, <a href='http://guides.rubyonrails.org/active_record_querying.html'>Active Record Query Interface</a>, <a href='http://guides.rubyonrails.org/configuring.html'>Configuring Rails Applications</a>, <a href='http://guides.rubyonrails.org/engines.html'>Getting Started with Engines</a> and the <a href='http://guides.rubyonrails.org/initialization.html'>Rails Initialization Internals</a> guides. I've also been known to hang out on <a href='http://stackoverflow.com/users/15245/ryan-bigg'>Stack Overflow</a>.
</p>
<p><strong>If you're a recruiter, thanks but no thanks. Please do not contact me.</strong></p>
<p> Occasionally I find some time to write interesting blog posts such as the ones you see below.</p>
<p>I also have done quite a lot of <a href="http://github.com/radar">open-source work</a> and I <a href="http://twitter.com/ryanbigg">tweet</a>. Find out more <a href="http://ryanbigg.com/about-me">about me</a>.</p>
<p>If you like what you see you can <a href='http://feeds.feedburner.com/ryanbigg'>subscribe to this blog</a>.</p>
</div>
</div>
<header></header>
<!-- Layout inspired by Nick Quaranto's "Litany Against Fear" blog
http://litanyagainstfear.com -->
<div id='page'>
<article>
<a href="/2013/09/debugging-rails-controllers"><header>Debugging Rails Controllers</header></a>
<small>05 Sep 2013</small><br>
<p>Here's my flow for debugging a misbehaving controller. Imagine that there's a form at <code>app/views/messages/new.html.erb</code> that is posting to <code>MessagesController#create</code>. The parameters aren't being passed through from the form to the controller, and the model is raising a validation error saying that a field is blank -- even though it's <em>clearly</em> not.</p>
<h3>Step 0: Does restarting the server fix the problem?</h3>
<h3>Step 1: Check the form</h3>
<ul>
<li>Is the attribute defined in the correct place? </li>
<li>Is it using the form builder helper (i.e. <code>f.text_field</code>) or is it using <code>text_field_tag</code>? If it's supposed to be <code>params[:message][:body]</code> then it should be using the form builder. If not, then it should be using <code>text_field_tag</code> or similar.</li>
<li>Unlikely, but still possible: Is the field disabled before submission of the form? Disabled fields are not passed through as parameters.</li>
</ul>
<h3>Step 2: Check the controller</h3>
<ul>
<li>Is the route to the controller defined correctly in <code>config/routes.rb</code>?</li>
<li>Is the controller set up to receive the right parameters?</li>
<li>Did I spell 'message' with the correct number of 's's within <code>params[:message]</code>?</li>
<li>Are the parameters from the form permitted using strong_parameters?</li>
<li>Are <em>all</em> the parameters from the form permitted?</li>
<li>Did I spell the parameters correctly? </li>
<li>What does the log output say for this controller? Does it contain the parameters I want with the values I want?</li>
<li>Can I place a <code>binding.pry</code> statement at the top of the action and print out <code>params</code> to see the correct parameters there too?</li>
</ul>
<h3>Step 3: Check the model</h3>
<ul>
<li>If using <code>attr_accessible</code>, are the attribute marked as accessible?</li>
<li>Did I accidentally use <code>attr_accessor</code> when I meant to use <code>attr_accessible</code>?</li>
<li>Did I define a setter method for this attribute accidentally that doesn't actually set the attribute?</li>
<li>Is there a callback that unsets this parameter somehow?</li>
<li>If it's nested attributes that are being sent through, go check the nested model for the above.</li>
</ul>
</article>
</div>
<div id='archive'>
<h2>25 back</h2>
<ul>
<li><a href="/2013/08/bundler-local-paths">Bundler local paths</a><abbr>16 Aug 2013</abbr></li>
<li><a href="/2013/07/waiting-for-ajax-in-capybara">Waiting for AJAX in Capybara</a><abbr>09 Jul 2013</abbr></li>
<li><a href="/2013/06/finding-sql-queries-in-rails">Finding SQL queries in Rails</a><abbr>26 Jun 2013</abbr></li>
<li><a href="/2013/02/about-spec-support">About spec/support</a><abbr>02 Feb 2013</abbr></li>
<li><a href="/2013/01/multitenancy-with-rails">Multitenancy with Rails</a><abbr>21 Jan 2013</abbr></li>
<li><a href="/2013/01/a-story-about-scaffolding">A story about scaffolding</a><abbr>07 Jan 2013</abbr></li>
<li><a href="/2012/11/no-more-writing-for-manning">No more writing for Manning</a><abbr>12 Nov 2012</abbr></li>
<li><a href="/2012/11/i-didn-t-submit-a-talk-to-rubyconf-australia">I didn't submit a talk to RubyConf Australia</a><abbr>01 Nov 2012</abbr></li>
<li><a href="/2012/10/javascript-arrays-and-objects">JavaScript Arrays and Objects</a><abbr>03 Oct 2012</abbr></li>
<li><a href="/2012/05/on-hiring">On Hiring</a><abbr>25 May 2012</abbr></li>
<li><a href="/2012/05/how-not-to-hire-me">How not to hire me</a><abbr>25 May 2012</abbr></li>
<li><a href="/2012/05/engines-talk">Engines talk</a><abbr>19 May 2012</abbr></li>
<li><a href="/2012/04/caffeine-and-sleep">Caffeine and Sleep</a><abbr>27 Apr 2012</abbr></li>
<li><a href="/2012/04/integration-testing-engines">Integration testing engines</a><abbr>26 Apr 2012</abbr></li>
<li><a href="/2012/03/polymorphic-routes">Polymorphic Routes</a><abbr>27 Mar 2012</abbr></li>
<li><a href="/2012/03/please-learn-rails">Please learn Rails</a><abbr>17 Mar 2012</abbr></li>
<li><a href="/2012/03/frontier-we-need-to-talk">Frontier, we need to talk</a><abbr>14 Mar 2012</abbr></li>
<li><a href="/2012/03/engines-and-authentication">Engines and Authentication</a><abbr>03 Mar 2012</abbr></li>
<li><a href="/2012/01/free-help">Free Help</a><abbr>31 Jan 2012</abbr></li>
<li><a href="/2012/01/moving-out-down-to-melbourne">Moving Out: Down to Melbourne</a><abbr>09 Jan 2012</abbr></li>
<li><a href="/2011/12/matt-lightner">Matt Lightner</a><abbr>27 Dec 2011</abbr></li>
<li><a href="/2011/12/deciding-what-tests-to-write">Deciding what tests to write</a><abbr>05 Dec 2011</abbr></li>
<li><a href="/2011/11/don-t-print-hard-copies">Don't print hard-copies</a><abbr>29 Nov 2011</abbr></li>
<li><a href="/2011/11/screencast-wrong-argument-type">Screencast: wrong argument type</a><abbr>23 Nov 2011</abbr></li>
<li><a href="/2011/11/the-rails-api">The Rails API</a><abbr>14 Nov 2011</abbr></li>
</ul>
<center><a href='/blogography.html'>The Complete Blogography</a></center>
</div>
</div>
<script type="text/javascript">
var _gauges = _gauges || [];
(function() {
var t = document.createElement('script');
t.type = 'text/javascript';
t.async = true;
t.id = 'gauges-tracker';
t.setAttribute('data-site-id', '4e30f771f5a1f547c8000001');
t.src = '//secure.gaug.es/track.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(t, s);
})();
</script>
</body>
</html>