sqlite - Raw Database content showing up in Rails View -
you can see here seems raw contents of db being printed page. can't see anywhere in code why there raw output of db printed view. here code index view:
<div class="main"> <div="messages"> <%=@messages.each |t|%> <h2 class="subject"><%=t.subject%></h2> <p class="content"><%=t.content%></p> <% end %> <%=link_to "create message", edit_path%> </div> </div>
the create form/view:
<div class="formwrapper"> <%= form_for @messages |t|%> <div class ="inputs"> <%=t.text_field :subject%><br> <%=t.text_area :content%> <div class="submit"> <%=t.submit "submit"%> </div> <%end%> </div> </div>
the controller:
class messagescontroller < applicationcontroller def index @messages=message.all end def new @messages=message.new end def create @messages = message.new(message_params) if @messages.save redirect_to '/' else render 'new' end end private def message_params params.require(:message).permit(:content, :subject) end end
you don't need =
here: <%=@messages.each |t|%>
, equals sign telling erb show every message on view.
<% %>
will execute ruby code no effect on html page being rendered. output thrown away.
<%= %>
will execute ruby code , insert output of code in place of <%= %>
example...
<% puts "almost" %> nothing see here
render as
nothing see here
however
<%= puts "almost" %> nothing see here
would render as
almost nothing see here
Comments
Post a Comment