First of all, making DB calls in views
is a big NO! NO!
Secondly, to answer why you see the output as
#<Baseline:0x007f944c4f7f80>
for
<%= Baseline.create(subject_id: sub.subject_id) %>
You are trying to render an instance of Baseline
model. Its just how the instance would be displayed. If you want to display a particular attribute's value in view then just do
<%= Baseline.create(subject_id: sub.subject_id).subject_id %>
Also, this code will not create a link
. To create a link you would have to call link_to
helper in your view.
What you need to do is, move the Baseline.create
call in the controller. Set an instance variable in the action which renders this particular view as below:
def action_name
@baseline = Baseline.create(subject_id: sub.subject_id)
end
After this in you view you can easily access all the attributes of @baseline
instance.
For example:
To access subject_id
<%= @baseline.subject_id %>
To create a link for show page of @baseline
, provided you have a RESTful route to show
action for baselines
<%= link_to "Some Link", @baseline %>