I'm having a very difficult time figuring out why this text field is coming up blank. According to all of the Ruby tutorials I've read it should have the question's text value inside of it (as the value attribute in html).
Here is my markup:
<%= form_tag :action => "create" do |f| %>
<% @questions.each do |q| %>
<span><%=q.text %></span> <!-- This was a test, it displays it properly -->
<%= text_field :q, :text %> <!-- This is the problem line -->
<% end %>
<%= submit_tag %>
<% end %>
Here is my controller:
class Admin::QuestionsController < ApplicationController
# TODO: Validations
def new
@questions = Array.new
question = Question.new :text => 'winner'
@questions.push(question)
end
...
And here is my model:
class Question < ActiveRecord::Base
attr_accessible :text
end
Any help would be appreciated. The Span seems to properly be displaying the text, but the text_field won't display it inside
将行更改为
<%= text_field_tag 'field_id', q.text %>
Try these:
<%= f.text_field :text, :value => q.to_s %>
or
<%= text_field_tag :text, q.to_s %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.