Last active
January 11, 2016 20:06
-
-
Save bronson/568d10d1cda405881a9c to your computer and use it in GitHub Desktop.
Why can't the _property view call the search_params helper?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
helper_method :client_state # line 51 | |
def client_state | |
@client_state ||= ClientState.new(request, cookies) | |
end | |
helper_method :search_params # line 56 | |
def search_params | |
base_params = { pu: client_state.property_unit, lu: client_state.land_unit } | |
@search_params ||= Search::Params.new(base_params.merge(params)) | |
end | |
# (just demonstrating that a bunch of controllers need to call search_params as well) | |
def validate_search_params | |
if search_params.redirect_needed | |
redirect_to request.path + '?' + search_params.query_string | |
else | |
yield if block_given? | |
end | |
end | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SearchHelper | |
... | |
def preferred_readable_unit type # line 152 | |
uom = preferred_unit(type) | |
readable_unit(uom) | |
end | |
def format_uom title, value, uom, type, format="one_line" # line 157 | |
return if !good_value?(value) | |
pref = preferred_unit(type) | |
html = display_units(value, nil, uom, nil, pref) | |
render_propdata title, html, format | |
end | |
def format_property_size property, format # line 166 | |
if good_value?(property.lot_size) | |
pref = preferred_readable_unit(:land) | |
html = display_units(property.lot_size, nil, property.lot_size_uom, nil, pref) | |
render_propdata 'Lot Size', html, format | |
elsif good_value?(property.size_min) || good_value?(property.size_max) | |
pref = preferred_readable_unit(:property) | |
html = display_units(property.size_min, property.size_max, property.size_min_uom, property.size_max_uom, pref) | |
render_propdata 'Space Available', html, format | |
end | |
end | |
... | |
def preferred_unit type # line 202 | |
search_params.send("#{type}_unit") || client_state.send("#{type}_unit") | |
end | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- primary_contact = property.eager_primary_contact | |
.property.breakable{href: property_path_with_params(property)} | |
.row | |
.col-xs-4 | |
.row | |
.col-xs-5 | |
.icon-pictures | |
- if property.main_photo && property.main_photo.file_exists?('icon') | |
.picture | |
%img{src: property.main_photo.url('icon')} | |
- else | |
.picture-generic | |
.picture-caption | |
= property.type | |
.col-xs-7 | |
.row | |
.col-xs-12.data-section | |
.property-name= property.name | |
.location | |
!= property.address1 | |
- unless property.address2.blank? | |
!= property.address2 | |
- unless property.address3.blank? | |
!= property.address3 | |
.location= property.location | |
.col-xs-8 | |
.row | |
.col-xs-6 | |
.row | |
.col-xs-7.data-section | |
.prop-info | |
= format_property_size property, 'two_lines' | |
- unless property.contact_properties.empty? | |
.contact | |
.col-xs-6 | |
- if primary_contact | |
%span.nowrap= primary_contact.name | |
%span.nowrap= primary_contact.company_name.present? ? ' - ' + primary_contact.company_name : '' | |
%span.prop-value= primary_contact.telephone | |
.row | |
.col-xs-12 | |
.description= property.description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'search/print/_property.html.haml', type: :view do | |
it 'displays the page' do | |
property = build(:property) | |
render 'search/print/property', property: property | |
assert_select ":match('href', ?)", "/property/#{property.property_id}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(note that the above files are severely truncated so the line #s won't match) | |
1) search/print/_property.html.haml displays the page | |
Failure/Error: search_params.send("#{type}_unit") || client_state.send("#{type}_unit") | |
ActionView::Template::Error: | |
undefined local variable or method `search_params' for #<#<Class:0x007fb297cca2d0>:0x007fb297c7a280> | |
# ./app/helpers/search_helper.rb:203:in `preferred_unit' | |
# ./app/helpers/search_helper.rb:153:in `preferred_readable_unit' | |
# ./app/helpers/search_helper.rb:172:in `format_property_size' | |
# ./app/views/search/print/_property.html.haml:32:in `_app_views_search_print__property_html_haml___457751931363389149_70202514494660' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/template.rb:145:in `block in render' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `block in instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/template.rb:333:in `instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/template.rb:143:in `render' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/renderer/partial_renderer.rb:339:in `render_partial' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/renderer/partial_renderer.rb:310:in `block in render' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `block in instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/renderer/partial_renderer.rb:309:in `render' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/renderer/renderer.rb:47:in `render_partial' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/helpers/rendering_helper.rb:35:in `render' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/haml-4.0.7/lib/haml/helpers/action_view_mods.rb:12:in `render_with_haml' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/test_case.rb:199:in `render' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/actionview-4.2.5/lib/action_view/test_case.rb:120:in `render' | |
# ./spec/views/search/print/_property.html.haml_spec.rb:4:in `block (2 levels) in <top (required)>' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load' | |
# /Users/bronson/.gem/ruby/2.2.2/gems/spring-commands-rspec-1.0.4/lib/spring/commands/rspec.rb:18:in `call' | |
# -e:1:in `<main>' | |
# ------------------ | |
# --- Caused by: --- | |
# NameError: | |
# undefined local variable or method `search_params' for #<#<Class:0x007fb297cca2d0>:0x007fb297c7a280> | |
# ./app/helpers/search_helper.rb:203:in `preferred_unit' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment