Note that there are some explanatory texts on larger screens.

plurals
  1. POnoMethodError - undefined method. When using method from application_helper.rb
    primarykey
    data
    text
    <p>I receive a noMethodError when attempting to utilize a method in my application_helper file.</p> <p>It looks like the helper method itself is fine, but the code inside the helper method is whats triggering the error. I have double checked my model and schema files to be certain that I had the attributes listed correctly. A fresh pair of eyes on this would be well received.</p> <p>Here's my code...</p> <p>application_helper.rb</p> <p>PS. I'm showing both sets of helper methods here because this first set (Resident Helper Methods) works fine in the views it was intended for.</p> <pre><code> # START -- Resident Helper Methods def resident_full_name ([@resident.fname, @resident.lname] - [ '' ]).compact.join(' ') end def resident_dob @resident.dob end def resident_gender @resident.gender end def resident_doc_full_name ([@resident.doc_fname, @resident.doc_lname] - [ '' ]).compact.join(' ') end def resident_doc_phone1 @resident.doc_phone1 end def resident_doc_address @resident.doc_address end def resident_doc_city @resident.doc_city end def resident_doc_state @resident.doc_state end def resident_doc_zip @resident.doc_zip end def resident_guard_full_name @resident.guard_full_name end def resident_guard_phone @resident.guard_phone end def resident_desrep_full_name @resident.desrep_full_name end def resident_desrep_phone @resident.desrep_phone end # END -- Resident Helper Methods # START -- User Helper Methods def user_full_name ([@user.fname, @user.lname] - [ '' ]).compact.join(' ') end # END -- User Helper Methods # START -- User Helper Methods def user_full_name @user_full_name = ([@user.fname, @user.lname] - [ '' ]).compact.join(' ') return @user_full_name end # END -- User Helper Methods # START -- Admin Helper Methods def fac_owner_full_name @fac_owner_full_name = ([@admin.owner_fname, @admin.owner_lname] - [ '' ]).compact.join(' ') return @fac_owner_full_name end def fac_name @fac_name = @admin.fac_name return @fac_name end def fac_lic_num @fac_lic_num = @admin.lic_num return @fac_lic_num end def fac_address @fac_address = @admin.fac_address return @fac_address end def fac_state @fac_state = @admin.fac_state return @fac_state end def fac_zip @fac_zip = @admin.fac_zip return @fac_zip end def fac_email @fac_email = @admin.fac_email1 return @fac_email end def fac_phone @fac_phone = @admin.fac_phone1 return @fac_phone end # END -- Admin Helper Methods </code></pre> <p>show.html.erb</p> <pre><code>&lt;tr&gt; &lt;td&gt; &lt;label for="fac_name"&gt; &lt;b&gt;Name of Facility/Home&lt;/b&gt;&lt;br/&gt; logger.debug(fac_owner_full_name) &lt;%= fac_owner_full_name %&gt; &lt;%#= fac_name %&gt; &lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;label for="fac_lic_num"&gt; &lt;b&gt;License Number&lt;/b&gt;&lt;br /&gt; &lt;%#= fac_lic_num %&gt; &lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;label for="fac_email"&gt; &lt;b&gt;Email&lt;/b&gt;&lt;br /&gt; &lt;%#= fac_email %&gt; &lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;label for="fac_phone"&gt; &lt;b&gt;Phone&lt;/b&gt;&lt;br /&gt; &lt;%#= fac_phone %&gt; &lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;label for="fac_address"&gt; &lt;b&gt;Facility Address&lt;/b&gt;&lt;br /&gt; &lt;address&gt; &lt;%#= fac_address %&gt;&lt;br /&gt; &lt;%#= fac_city " " %&gt;&lt;%#= fac_state %&gt;&lt;br /&gt; &lt;%#= fac_zip %&gt; &lt;/address&gt; &lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;label for="fac_owner_full_name"&gt; &lt;b&gt;Licensee Name&lt;/b&gt;&lt;br /&gt; &lt;%#= fac_owner_full_name %&gt; &lt;/label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;label for="involved_person_full_name"&gt; &lt;%= @incident_accident_form.involved_person_full_name %&gt; &lt;/label&gt; &lt;/td&gt; </code></pre> <p>db/schema.rb</p> <pre><code>create_table "admins", :force =&gt; true do |t| t.string "owner_fname" t.string "owner_lname" t.string "lic_num" t.text "fac_address" t.string "fac_city" t.string "fac_state" t.string "fac_zip" t.string "fac_name" t.string "fac_phone1" t.string "fac_phone2" t.string "fac_phone3" t.string "fac_phone4" t.string "fac_phone5" t.string "fac_phone6" t.string "fac_phone7" t.string "fac_phone8" t.string "fac_phone9" t.string "fac_phone10" t.string "fac_phone11" t.string "fac_phone12" t.string "fac_phone13" t.string "fac_phone14" t.string "fac_phone15" t.string "fac_phone16" t.string "fac_phone17" t.string "fac_phone18" t.string "fac_phone19" t.string "fac_phone20" t.string "fac_phone21" t.string "fac_phone22" t.string "fac_phone23" t.string "fac_phone24" t.string "fac_phone25" t.string "fac_phone26" t.string "fac_phone27" t.string "fac_phone28" t.string "fac_phone29" t.string "fac_phone30" t.string "fac_email1" t.string "fac_email2" t.string "fac_email3" t.string "fac_email4" t.string "fac_email5" t.string "fac_email6" t.string "fac_email7" t.string "fac_email8" t.string "fac_email9" t.string "fac_email10" t.datetime "created_at", :null =&gt; false t.datetime "updated_at", :null =&gt; false end </code></pre> <p>models/admin.rb</p> <pre><code>class Admin &lt; ActiveRecord::Base attr_accessible :fac_address, :fac_city, :fac_name, :fac_state, :fac_zip, :lic_num, :owner_fname, :owner_lname, :fac_phone1, :fac_phone2, :fac_phone3, :fac_phone4, :fac_phone5, :fac_phone6, :fac_phone7, :fac_phone8, :fac_phone9, :fac_phone10, :fac_phone11, :fac_phone12, :fac_phone13, :fac_phone14, :fac_phone15, :fac_phone16, :fac_phone17, :fac_phone18, :fac_phone19, :fac_phone20, :fac_phone21, :fac_phone22, :fac_phone23, :fac_phone24, :fac_phone25, :fac_phone26, :fac_phone27, :fac_phone28, :fac_phone29, :fac_phone30, :fac_email1, :fac_email2, :fac_email3, :fac_email4, :fac_email5, :fac_email6, :fac_email7, :fac_email8, :fac_email9, :fac_email10 # has_many :users # validate_on_create :user_count_within_bounds private def user_count_within_bounds return if users.blank? errors.add("") if users.length &gt; 10 errors.add("") if users.length &gt; 25 end end </code></pre> <p><strong>UPDATED 01-17-13 11:30PM EST</strong> output from server</p> <pre><code>Started GET "/residents/1/incident_accident_forms/11" for 127.0.0.1 at 2013-01-17 23:23:57 -0500 Processing by IncidentAccidentFormsController#show as HTML Parameters: {"resident_id"=&gt;"1", "id"=&gt;"11"} Resident Load (1.0ms) SELECT "residents".* FROM "residents" WHERE "residents"."id" = $1 LIMIT 1 [["id", "1"]] IncidentAccidentForm Load (1.3ms) SELECT "incident_accident_forms".* FROM "incident_accident_forms" WHERE "incident_accident_forms"."resident_id" = 1 AND "incident_accident_forms"."id" = $1 LIMIT 1 [["id", "11"]] Rendered incident_accident_forms/show.html.erb within layouts/application (6.3ms) Completed 500 Internal Server Error in 14ms ActionView::Template::Error (undefined method `owner_fname' for nil:NilClass): 12: &lt;b&gt;Name of Facility/Home&lt;/b&gt;&lt;br/&gt; 13: logger.debug(fac_owner_full_name) 14: 15: &lt;%= fac_owner_full_name %&gt; 16: &lt;%= fac_name %&gt; 17: &lt;/label&gt; 18: &lt;/td&gt; app/helpers/application_helper.rb:74:in `fac_owner_full_name' app/views/incident_accident_forms/show.html.erb:15:in `_app_views_incident_accident_forms_show_html_erb__403107391156795487_2183850600' Rendered /Users/beracus/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.5ms) Rendered /Users/beracus/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms) Rendered /Users/beracus/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (9.4ms) </code></pre> <p><strong>UPDATED</strong> incident_accident_forms_controller.rb</p> <pre><code>class IncidentAccidentFormsController &lt; ApplicationController before_filter :get_resident before_filter :get_admin def index @incident_accident_forms = @resident.incident_accident_forms end def new @incident_accident_form = @resident.incident_accident_forms.build end def create @incident_accident_form = @resident.incident_accident_forms.build(params[:incident_accident_form]) if @incident_accident_form.save redirect_to [@admin, @resident, @incident_accident_form] #, flash[:success] = "Form was created!" else render 'new', flash[:error] = "There was a problem with the form" end end def show @incident_accident_form = @resident.incident_accident_forms.find(params[:id]) end def update @incident_accident_form = @resident.incident_accident_forms.find(params[:id]) if @incident_accident_form.update_attributes(params[:incident_accident_form]) flash[:success] = "Form updated!" redirect_to controller: 'residents', action: 'show', id: params[:id] else render 'edit', flash[:error] = "Unable to update form" end end def edit @incident_accident_form = @resident.incident_accident_forms.find(params[:id]) end def destroy @incident_accident_form = @resident.incident_accident_forms.find(params[:id]) @incident_accident_form.destroy flash[:notice] = "You sure?" redirect_to resident_incident_accident_forms_path end private # get_resident converts the resident_id given by the routing # into an @resident object, for use in this controller &amp; coresponding views def get_resident @resident = Resident.find(params[:resident_id]) end def get_admin @admin = Admin.find(params[:admin_id]) end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload