ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

issue with ____ #242

Closed kairajohnson closed 8 years ago

kairajohnson commented 8 years ago

I tried to define a method I will be using in my view in my model. I expected the method to be recognized since its in my posts.rb file and view but it showed as undefined instead.

My repo link is https://github.com/kairajohnson/live-unapologeticallyand my question is about lines 45 in my index.html.erb file for posts and posts.rb file in my model.

my model

class Post < ActiveRecord::Base

  def recent_posts
    image_tag post.featured_image
    post.title
    post.content
  end
end

my posts controller

class PostsController < ApplicationController

 def index
   @posts = Post.all
   params.permit(:featured_image)
 end

 def new
   @post = Post.new
 end

 def create
   @post = Post.create!(post_params)
   @post.save
   redirect_to @post
 end

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

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

 def update
   @post = Post.find(params[:id])
   @post.update(post_params)
   redirect_to @post
 end

 def destroy
   @post = Post.find(params[:id])
   @post.destroy
   redirect_to posts_path(@post)
 end

 private
 def post_params
   params.require(:post). permit(:title, :content, :featured_image, :featured_video, :category)
 end
end

my html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Unapologetic</title>
  </head>
  <body>

    <div id = "featured-post" style="text-align: center; padding-top: 35px;">
      <%= image_tag Post.last.featured_image, style:'max-width: 700px; height: auto'%>
      <h1 class="featured_title" style="padding-top: 15px; color: pink;"><%= Post.last.title %></h1>
      <div class="featured_content" style="padding: 0px 100px; width: 800px; margin: 0 auto;"><%= Post.last.content %></div>
    </div>

<div id="section-title" style="padding-top: 100px;">
<h1 class="section-title-left"style="width: 70%;"> In Her Closet </h1>
<h1 class="section-title-right"style="width: 30%;"> Recent Posts </h1>
</div>

<div id="main">

  <table id="grid" style="width: 66.66%; float: left;">
    <% @posts.in_groups_of(2, false) do |post_column| %>
    <tr>
        <% for post in post_column %>
        <td class="grid-post" style="width: 33.33%;">
          <h2 class="caption"><%= post.title %>
          </h2>
          <div id="thumbnail">
          <%= image_tag post.featured_image, :class=>"thumbnail"%>
          </div>
          <p><%= truncate(Post.last.content, length: 200) %></p>
        </td>
        <% end %>
      <tr>
      <% end %>
  </table>

  <div id="sidebar" style="float: right;">
    <div id="recent-posts">
      <h2> Recent Posts </h2>
      <table>
        <tr>
          <%= recent_posts %>
        </tr>

  </div>
</div>

  </body>
</html>
kairajohnson commented 8 years ago

https://github.com/kairajohnson/live-unapologetically

RobertAKARobin commented 8 years ago

You posted this on Project 1, Kaira. Can you please repost to Project 2?

kairajohnson commented 8 years ago

Apologies, I clicked on the links in our lesson plan for project 2. Took me to asking for help and provided that link. Didn't notice it was 2 On Mar 22, 2016 5:05 PM, "Robert Thomas" notifications@github.com wrote:

You posted this on Project 1, Kaira. Can you please repost to Project 2?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/ga-wdi-exercises/project1/issues/242#issuecomment-200026558

kairajohnson commented 8 years ago

Wrote that wrong. To clarify, the link in project 2 that links to asking for help links to project 1. Will resend On Mar 22, 2016 5:08 PM, "K Johnson" kjohnson1913@gmail.com wrote:

Apologies, I clicked on the links in our lesson plan for project 2. Took me to asking for help and provided that link. Didn't notice it was 2 On Mar 22, 2016 5:05 PM, "Robert Thomas" notifications@github.com wrote:

You posted this on Project 1, Kaira. Can you please repost to Project 2?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/ga-wdi-exercises/project1/issues/242#issuecomment-200026558