嘿,我有一个 Rails 应用程序,我正在用回形针上传图像....
所以我有一个comic_review 脚手架,我可以上传漫画封面的图片,我还有一个新闻脚手架,我可以在其中发布新闻和图片.....
当我编辑 news/1/edit 并上传图片时,comics_review/1 图片与新闻图片相同,反之亦然。
我检查了视图中的链接以确保我是正确的并且它们似乎没问题...
这是我的看法
主页.html.erb
<h2 style="color: black; font-size: 30px;"><%= @comic_review1.title %></h2>
<p><%= @comic_review1.content %></p>
<%= link_to 'Read More...', comic_review_path(@comic_review1) %>
<%= image_tag @comic_review1.photo, class: "homepage_comics" %>
新闻/show.html
<%= @news.author %>
<%= @news.date %>
<%= image_tag @news.photo, class: 'pull-left', style: 'margin-right: 10px;' %>
这是我的控制器
static_pages_controller.rb
class StaticPagesController < ApplicationController
def home
@user = current_user
@article = Article.first
@comic_review1 = ComicReview.find(1)
@comic_review2 = ComicReview.find(2)
@comic_review3 = ComicReview.find(3)
@comic_review4 = ComicReview.find(4)
end
def comics
@comic_review1 = ComicReview.find(1)
@comic_review2 = ComicReview.find(2)
@comic_review3 = ComicReview.find(3)
@comic_review4 = ComicReview.find(4)
end
def batnews
@article = Article.first
@news_all = News.all
end
end
这是我的模型
漫画评论.rb
class ComicReview < ActiveRecord::Base
attr_accessible :content, :credits, :review, :title, :photo, :comicreview
has_attached_file :photo, :styles => { :small => '400x400' },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/activities/:id/:style.:extension",
:bucket => 'goddam_batman_pics'
has_many :comments, as: :commentable, dependent: :destroy
end
新闻.rb
class News < ActiveRecord::Base
attr_accessible :title, :author, :date, :content, :photo
has_attached_file :photo, :styles => { :small => '400x400' },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":attachment/activities/:id/:style.:extension",
:bucket => 'goddam_batman_pics'
end
控制器是由脚手架生成的基本控制器
因此,每当我为 news/1 更新照片时,comic_reviews/1 的照片都会获得与 news 相同的照片
任何帮助将不胜感激谢谢