fynn
fynn

Reputation: 143

Access a model variable from another controller page

Setting which functions as a post. It has the variables: Title:string Description:text, Photo:image and Paragraph:text.

I have another controller which controls my Home, About, News and contact.
On my Home, I'm trying to access the title of the setting with the id 3. I can't figure it out. Do i need to define the controls for the settings in the page controller as well? How can I access it?.

Here is my code at the Home,

<% @setting.(id[3]) do |setting| %>
<h2><%= setting.title %></h2>
<% end %>

Error: Undified local varible or method 'id' for #<#

Would appreciate some help, or a push in the right direction. Thanks :)

Upvotes: 0

Views: 1101

Answers (1)

Amit Sharma
Amit Sharma

Reputation: 3477

If you want to display single record then there is no need to have loop, so you can try this.

<% setting = Setting.find(3) %>
<h2><%= setting.title %></h2>

Upvotes: 3

Related Questions