•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Ruby section within the Web Development category of DaniWeb, a massive community of 375,231 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,217 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Views: 1790 | Replies: 3 | Solved
![]() |
•
•
Join Date: Mar 2005
Location: Nebraska, U.S.
Posts: 186
Reputation:
Rep Power: 4
Solved Threads: 4
Hey everyone,
I am new to Ruby on Rails and I am having a problem that I can't seem to figure out. I have a mysql database that I created and I have created a model for it. I have did not create a migration, as the database is already full of information. I added a scaffold to the application, and it showed the data from the database with no problems.
I have tried to create a new controller called portfolio, and in this I have an index. Here is the controller code:
The @stocks is, from what I understand, supposed to contain the rows returned from the database. Below is my Stock Model code:
Finally, I have a view created in app/views/portfolio/index.rhtml Below is the code from there:
in the database table, I have a column named stock_symbol. When I try and access this view in a web browser, I get the following error message:
I don't understand why I am seeing this. Anyone have any ideas?
Thanks for the help in advance.
Nick
I am new to Ruby on Rails and I am having a problem that I can't seem to figure out. I have a mysql database that I created and I have created a model for it. I have did not create a migration, as the database is already full of information. I added a scaffold to the application, and it showed the data from the database with no problems.
I have tried to create a new controller called portfolio, and in this I have an index. Here is the controller code:
class PortfolioController < ApplicationController
def index
@stocks = Stock.find_active_symbols
end
endThe @stocks is, from what I understand, supposed to contain the rows returned from the database. Below is my Stock Model code:
class Stock < ActiveRecord::Base
def self.find_active_symbols
find(:all, :order => "stock_symbol")
end
endFinally, I have a view created in app/views/portfolio/index.rhtml Below is the code from there:
<% for st in @stocks -%> <%= h(st.stock_symbol) %> <% end %>
in the database table, I have a column named stock_symbol. When I try and access this view in a web browser, I get the following error message:
undefined method `stock_symbol' for #<Stock:0xb72e11a4>
I don't understand why I am seeing this. Anyone have any ideas?
Thanks for the help in advance.
Nick
•
•
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation:
Rep Power: 3
Solved Threads: 31
Looking at your code I can't see whats wrong.
What happens if in your view you do
It may give a clue as to what's wrong.
What happens if in your view you do
<% for st in @stocks -%> <%= h(st.inspect) %><br /> <% end %>
It may give a clue as to what's wrong.
Note to self... pocket cup
•
•
Join Date: Jan 2005
Location: San Jose, CA
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 1
Since you're working with a MySQL database that's already full of data, do they follow Rails conventions? I.e., are the table names plural (e.g., the table corresponding to the Stock model should be named "stocks") and does each table with a Rails model class have an "id" field that's its primary key?
If not, that would cause problems (though I'm not sure if it would cause the problem you're seeing at the moment).
Ed
If not, that would cause problems (though I'm not sure if it would cause the problem you're seeing at the moment).
Ed
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Ruby Marketplace
- Previous Thread: My first Ruby programming question :-)
- Next Thread: Amazon-Ecs Local Download Slow on Leopard


Linear Mode