0

Hopefully this is a little clearer. I'm sorry but I'm very new to coding in general. I have multiple tables that I have to query in succession in order to get to the correct array that I need. The following logic for the query is as follows:

this gives me an array based upon the store :id

store = Stores.find(params[:id])

this gives me another array based upon the param .location found in the table store where that value equals the row ID in the table Departments

department = Departments.find(store.location)

I need to preform one last query but in order to do so I need to figure out which day of the meeting is needed. In order to do this I have to create the parameter day_of_meeting found in the table Stores. I try to call it from the array above and create a new variable. In the Table Departments, I there are params such as day_1, day_2 and so on. I need to be able to call something like department.day_1 or department.day_2. Thus, I'm trying to actually create the variable by join the words "department.day_" to the variable store.day_of_meeting which would equal some integer, creating department.day_1...

which_day = ["department.day_", store.day_of_meeting].join("")

This query finds uses the value found from the variable department.day_1 to query table Meeting to find the values in the corresponding row.

meeting = Meeting.find(which_day)

Does this make my problem any clearer to understand?

5
  • You should do it in model. Commented Jun 16, 2014 at 11:44
  • Do you mind explaining how I can define that logic in the model? Commented Jun 16, 2014 at 21:13
  • I read your question over and over and I'm not even sure if I understand what you mean at all (it makes no sense to me) but since you don't use params a single time but make heavy use of object (model) attributes I guess controller is a wrong place to put it. Again, I think I don't understand what you want to achieve. Commented Jun 16, 2014 at 21:29
  • I re-wrote the question so hopefully it is a little clearer. Does it make any sense? Commented Jun 16, 2014 at 22:31
  • when you say this gives me an array.... You're wrong, Stores.find(your_id) is an ActiveRecord object Commented Jun 16, 2014 at 23:03

1 Answer 1

2

findmethod can only accept parameters like Meeting.find(1) or Meeting.find("1-xx").

so, what you need is Meeting.find(department.send("day_" + store.day_of_meeting.to_s))

Hope to help!

Sign up to request clarification or add additional context in comments.

3 Comments

I get "no implicit conversion of Fixnum into String". The value is an integer so does it have to do with adding the text "day_" + the inetger (store.day_of_meeting)?
that is because store.day_of_meeting return integer, so need to convert it to string, i have updated!
perfect. thank you. I kept using .to_i - dumb on my part

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.