0

I'm working on Rails 3.2.9 app with ruby 1.9.3 and mysql as my DB . I want to retrieve a particular column data called 'no_of_tc'from a model named "excel_file' but i dont have the primary key/id of tat row . All i have is the filename.

tc_no = ExcelFile.find(35).no_of_tc gives me the result but i dont have id all the time

tc_no = ExcelFile.find_by filename: 'excel_name' gives the error "unknown method - find_by"

How can i get the required data without having the primary key?? and why am I getting unknown method error for 'find_by'

1 Answer 1

1

I am assuming :file_name is another attribute of ExcelFile class.

try:

tc_no = ExcelFile.find_by_file_name(#name_of_the_fie)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot that worked:):) tc_no = ExcelFile.find_by_file_name(#name_of_the_fie).no_of_tc gave me the data i wanted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.