0

I have two Model user and speed

User Model contain

name,email,password,id_watch all this get from sign up In addition to user_id

speed Model contain

id_watch,x_speed,y_speed all this already add by watch device

need when user sign up then enter id_watch get all id_watch data

when id_watch from user table equal id_watch from speed table

7
  • Speed.where(id_watch: current_user.id_watch) nor use .find if want to return just one id_watch Commented Jun 23, 2018 at 7:39
  • must association between two table @ 7urkm3n ? Commented Jun 23, 2018 at 7:49
  • as i understand, you dnt need assoc' for this kind part. Commented Jun 23, 2018 at 7:51
  • yes but i asked you must or not ? Commented Jun 23, 2018 at 8:21
  • if speed model is just public data and want to make sure user interest == to public data then no need. It all depends how modeling an application. Commented Jun 23, 2018 at 8:25

1 Answer 1

2

You can create smth like this. Association is not important for this.

#view pages
<% @speed_data.each do |sd| %>
   <%= "#{sd.x_speed} : #{sd.y_speed}" %>
<% end %>

#in controller where using current_user or user object
#sample
def index
   @speed_data = current_user.speed_data
end

# models/user.rb
class User < ApplicationRecord
   def speed_data
      Speed.where(id_watch: self.id_watch)
   end
end

# models/speed.rb
class Speed < ApplicationRecord
end
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you @7urkm3n

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.