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

  • Home
  • SEARCH
  • 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 7055895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:48:11+00:00 2026-05-28T03:48:11+00:00

brief update I might not even bother with a form to submit the data

  • 0

brief update
I might not even bother with a form to submit the data to the database and instead just use Heroku console, so my only concern is retrieving it.

Original Question

I’ve read all the books but now that I’m trying to implement I’m getting confused

I created a model named Total (not the best name, but that’s another problem) with three columns, profit, number and fees. Here’s the console printout

t = Total.first
 => #<Total id: 1, profit: 500, number: 7, fees: 40, created_at: "2012-01-12 04:21:33", updated_at: "2012-01-12 04:21:58"> 

(Note, I assume that this entry will be available to present at localhost:3000 if made on the development database)

The easiest place for me to present this data (due to my webpage layout) is in application.html.erb so I’ve got a little table like this. When you look at this table, you can see how I wish to present the data by calling ‘profit’ on an instance variable @t.profit @t.number and @t.fees.

<table class = "condensed-table" >
        <thead>
          <tr>

            <th>Profit </th>
            <th>Number of Trades</th>
            <th> Fees</th>
          </tr>
        </thead>
        <tbody>
          <tr>


            <td>$<%= @t.profit  %> </td>
            <td><%=  @t.number %></td>
            <td><%=  @t.fees %></td>
          </tr>
          </tbody>
      </table>

So now it’s only a question of getting the data from the database, and creating the instance variable so I can call @t.profit, just like I did in the console

ruby-1.9.2-p290 :019 > t.profit
 => 500 

So with a Total.rb model and presentation in application.html.erb, I figured I needed to do this ….

@t = Total.find(params[:id])

to get the data from the database, but what should I call the method and where should i put it to make it work?

For example, if I had a pages controller and a pages view, I could just create an index action in the view like

def index
@t = Total.find(params[:id])
end

and then I could just do @t.profit (i assume). However, if I did something like that my table to present the data wouldn’t be available on every part of my site.

I tried to put it in application_controller.rb

 def index

    @t = Total.find(params[:id])

  end

and got this error message

NoMethodError in Posts#index

Showing /Users/me/Sites/enki2/app/views/layouts/application.html.erb where line #73 raised:

undefined method `profit' for nil:NilClass

Extracted source (around line #73):
  • 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-05-28T03:48:12+00:00Added an answer on May 28, 2026 at 3:48 am

    You can do this via a filter hook – it allows a method (or several methods) to be called for all actions, and if needed, for all controllers. You can also explicitly exclude it from firing for certain actions and controllers. See – http://apidock.com/rails/ActionController/Filters/ClassMethods/before_filter

    However, in your case you probably won’t have params[:id] available in every action call for every controller. If the table needs to be included as part of your general layout, you will probably need an id that doesn’t change. You can use the acts_as_singleton plugin for this – https://github.com/stephencelis/acts_as_singleton. Then you can use this in the partial itself:

        <% @t = Total.instance -%>
        <td>$<%= @t.profit  %> </td>
        <td><%=  @t.number %></td>
        <td><%=  @t.fees %></td>
    

    Or you can simply assume it will always be the first:

        <% @t = Total.first -%>
        <td>$<%= @t.profit  %> </td>
        <td><%=  @t.number %></td>
        <td><%=  @t.fees %></td>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brief question What command can I use to make my DataSet refresh it's connection
Could anybody brief about user_token functionality in Auth module? What is a use and
Brief googling looks like you're supposed to use MarkupBuilder, but I don't understand it.
Brief description of requirements (Lots of good answers here, thanks to all, I'll update
I want brief knowledge about Data Template for Customizing a control(like Combo Box,List Box
The example will give a brief explanation of what i'm talking about: AFTER INSERT,UPDATE
In brief: Is it ever excusable to have assembly names and class names stored
A brief preface: I'm in a game design class where our project for the
I happened upon a brief discussion recently on another site about C# runtime compilation
I'll keep this brief. I am trying to keep a map between strings and

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.