show.html.erb and html tags

21 views
Skip to first unread message

baron visi

unread,
Sep 26, 2013, 6:57:03 PM9/26/13
to rubyonra...@googlegroups.com
Hi there.

I have a problem about accessing posts/show.html.erb

i can listing all posts on index.html.erb but when i try to access any
post html tags are not shown in show.html.erb, like images.

------------------
Controller

class PostsController < ApplicationController
before_action :postu_belirt, only: [:show, :edit, :update, :destroy]
http_basic_authenticate_with name: "esss", password: "birki"

def index
@posts = Post.all
end

def show
end
end

-----------------

index.html.erb

<% @posts.each do |post| %>
<%= link_to post.baslik, post, :class => "baslik"%>
<%= post.created_at.strftime("%d %b %y") %>
<%= post.created_at.strftime("%H:%M") %>
<%= raw post.text %>
<%- end %>
----------------------

show.html.erb

<%= @post.baslik %>
<%= @post.created_at.strftime("%d %b %y") %>
<%= @post.created_at.strftime("%H:%M") %>
<%= link_to 'Duzenle', edit_post_path(@post), :class => "genel" %>
<%= raw @post.text %>

Thanks.

--
Posted via http://www.ruby-forum.com/.

John Moon

unread,
Sep 27, 2013, 4:18:48 PM9/27/13
to rubyonra...@googlegroups.com
Hey,

I'm assuming your show page is displaying an individual item from the index page. From that information I would put "@post = Post.find(params[:id])" in the Show action. This will look for the single page E.G ( www.example.com/1) number 1 in this example. Also, <%- end %>   you have a dash. Change it to <% end %>. You also might want to clean it up like this, just my preference.

<h1><%=  @post.baslik %> </h1>
<p><%=  @post.created_at.strftime("%d %b %y") %> </p>
<p><%=  @post.created_at.strftime("%H:%M") %> </p>
<p><%=  link_to 'Duzenle', edit_post_path(@post), :class => "genel" %> </p>
<p><%=  raw @post.text %> </p>

This way it just looks cleaner and it'll look better. I'm not familiar with strttime so I can't help you with that one. I'm also confused why you are calling the class symbol => genel ? What does that do.  

Let me know.
Reply all
Reply to author
Forward
0 new messages