Displaying foreign key value

Hi

i have a has_many app. Imagine Projects <> Tasks.
Creating a new tasks i can select from the dropdown the desired Project.
that works. Editing the taks , which means changing the project
association again via dropdown works as well. BUT and thats the
question:
how do i display the project name in the tska/show view?
Task:
<%=h @task.title %>
Task-Desc:
<%=h @task.desc %>
Project:
<%=h @Project.title %> ???
OR
<%=h render :text => Project.find_by_id(@task.project_id) %>

HOW is ths working?

thx tom

<%=h @Project.title %> ???
OR
<%=h render :text => Project.find_by_id(@task.project_id) %>

HOW is ths working?

if in your Task model, you have

belongs_to :project

then in your view

@task.project.title

thx, i totally oversaw the missing relations…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs