I have two tables: one called styles, which has 5 attributes (plus id and created_at) and another called recommender, which has 6 attributes (plus id and created_at).
Once I have defined the 5 attributes on the Styles table, I want to be able to show an entry from the recommender table that has 5 attributes matching the attributes in the styles table.
I have tried a few combinations of Model.find and Model.where to get it, but nothing seems to work.
Here is the styles_controller.rb
def show
@style = Style.find(params[:id])
bt = @style.bodytype
n = @style.need
t = @style.texture
c = @style.color
st = @style.statement
@recommender = Recommender.with_bodytype(params[:bt]).with_need(params[:n]).with_texture(params[:t]).with_color(params[:c]).with_statement(params[:st])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @style }
end
end
The message I get is:
Undefined method `with_bodytype’ for #
So, thanks to @bravenewweb for helping out… But there are still some issues:
I think I figured out the problem, but I am not sure how to fix it.
The production environment has Recommender with all its data (I put it there) and so does development.
Recommender exists now at Heroku, but not with any data. And I am not sure how to put it there.
I think the problem is that the Production db is SQLite, even though it is only supposed to work in development and test. So how do I get the production db to talk to Heroku?
Please help!
It should be much easier than that, ActiveRecord’s find method will by default return the first record that matches. What you want to do is chain the attribute names with and, then pass the query attributes in using the same order as the method name
If you want to find all the records matching those params, you just need to start it with