Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7769609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:12:06+00:00 2026-06-01T16:12:06+00:00

For example, I’m placing the partial <%= render layouts/location %> in views all over

  • 0

For example, I’m placing the partial <%= render "layouts/location" %> in views all over the site. I need a controller for the layout (I tried layouts_controller.rb ) so I could do

def _location
    @city = request.location.city
    @state = request.location.state
  end

The partial contains the code <%= @city %>, <%= @state %>

This is all effectively, supposed to display the city and state of the visitor on whatever page the partial is rendered on.

When I do this however, and push to heroku and migrate the database, I’m served the error:
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

So the question is, how do I define a function for a partial?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:12:08+00:00Added an answer on June 1, 2026 at 4:12 pm

    You could do this in a before filter in your application controller like so:

    ...
    before_filter :location
    
    def location
        @city = request.location.city
        @state = request.location.state
    end
    

    The name of the method needs to match the symbol in the before_filter call, but other than that, you can call the method whatever you want. The method must be in the ApplicationController class though.

    Clarification: This will get called before every request in your application and set these two instance variables for you, so in every view, you will always and automatically have access to @city and @state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: find / * Gives me all files and directories, but I want only
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
%example clear all a1 = struct('data1',rand(12,2),'data2',rand(12,2),'data3',rand(12,3)); a2 = struct('data1',rand(12,2),'data2',rand(12,2),'data3',rand(12,3)); a3 = struct('data1',rand(12,2),'data2',rand(12,2),'data3',rand(12,3)); a4 =
Example page is: http://www.uswitch.com/mobiles/deals/apple_iphone_4s/ This page aggregates all contract deals for a specific handset,
Example CSV line: 2012,Test User,ABC,First,71.0,,,0,0,3,3,0,0,,0,,,,,0.1,,4.0,0.1,4.2,80.8,847 All values after First are numeric columns. Lots of
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
Example: select ename from emp where hiredate = todate('01/05/81','dd/mm/yy') and select ename from emp
example: a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works Python
example: I want to see if array[5] holds a value or is empty.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.