0

I'm stuck. On edit I grab a handful of data from the database and print the values in input fields. That part is working well. I want to print on the values without using a text field but can't seem to figure out how.

Form:

 <%= form_for(@post, :html => {:multipart => true}) do |f| %>

Currently working for printing my title value from the database into text field:

 <%= f.text_field :title, :size => "65%" %>

Controller:

def edit
    @post = Post.find(params[:id])
end

I've tried quite of bit of variations, but I'm a newbie.

<%= post.title %>
<%= @post.title %>
<%= f.title %>
<%= :title %>(lol)

Thanks in advance for the help!

2
  • <%= @post.title %> should work. what is your error? Commented Aug 26, 2013 at 1:42
  • No value is printed whatsoever when i view the html output. Commented Aug 26, 2013 at 1:45

1 Answer 1

2

Few things you can try:

1) Verify that the post with the ID really has a title.

rails c, then p = Post.find_by_id(5) (assuming that's the params[:id]) then check with p.title

2) There are 2 ways you can print the title. One way you have already tried @post.title. The other way is f.object.title. Therefore, only the second of your variations work.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the rails console tip. I need to start using that. I know some mysql pretty well but very new to sqlite. There was no title for the record lol. Thanks for the sanity check! @post.title on a record with a title prints just fine.
No problem! Rails console is your friend. :)

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.