2016-01-28 5 views
0

У меня есть много изображений (add_images_to_steps), принадлежащих шагам, принадлежащим diys. Вся информация сохраняется правильно, как показывает браузер БД, но у меня проблемы с просмотром изображений.CarrierWave undefined method `image_url 'или поврежденное изображение

с просмотров/DIYs/show.html.erb

<p id="notice"><%= notice %></p> 
    <h2><%= @diy.summary %></h2> 
     <% @steps.each do |step| %> 
     <p><%= step.step_content %></p> 
     <% step.add_images_to_steps.each do |i| %> 
      <%= image_tag i.image_url.to_s %> 
     <% end %> 
    <% end %> 

я NoMethodError в DIYs # Показать

неопределенный метод `IMAGE_URL» для #

и если я изменю

в

I get this

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

Heres Мои миграции, модели и контроллеры.

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

diys_controller.rb

class DiysController < ApplicationController 
    before_action :set_diy, only: [:show, :edit, :update, :destroy] 

def show 
    @diy = Diy.find(params[:id]) 
    @steps = @diy.steps.all 
    @diy.add_images_to_steps.all 
end 

def new 
    @diy = Diy.new 
    @step = @diy.steps.new 
    @step.add_images_to_steps.new 
end 

... 

def diy_params 
    params.require(:diy).permit(:title, :summary, :tip, :warning, steps_attributes: [:step_content, add_images_to_steps_attributes: [:image]]) 
end 

модели/diy.rb

class Diy < ActiveRecord::Base 
    has_many :steps, dependent: :destroy 
    accepts_nested_attributes_for :steps, reject_if: :all_blank 
    has_many :add_images_to_steps, :through => :steps, dependent: :destroy 
    accepts_nested_attributes_for :add_images_to_steps 
end 

модели/step.rb

class Step < ActiveRecord::Base 
    belongs_to :diy 
    has_many :add_images_to_steps, dependent: :destroy 
    accepts_nested_attributes_for :add_images_to_steps 
    mount_uploader :image, ImageUploader 
end 

модели/add_images_to_step.rb

class AddImagesToStep < ActiveRecord::Base 
    belongs_to :step 
end 

Diy миграция

class CreateDiys < ActiveRecord::Migration 
    def change 
    create_table :diys do |t| 
     t.string :title 
     t.text :summary 
     t.text :tip 
     t.text :warning 
     t.timestamps null: false 
    end 
    end 
end 

Этапы миграции

class CreateSteps < ActiveRecord::Migration 
    def change 
    create_table :steps do |t| 
     t.belongs_to :diy 
     t.text :step_content 
     t.timestamps null: false 
    end 
    end 
end 

add_images_to_step миграция

class CreateAddImagesToSteps < ActiveRecord::Migration 
    def change 
    create_table :add_images_to_steps do |t| 
     t.belongs_to :step 
     t.string :image 
     t.timestamps null: false 
    end 
    end 
end 
+0

Попробуйте image_path int image_url – Ezequiel

+0

Не работает :(Но спасибо в любом случае –

ответ

0

Я понял это !!

бы добавить

mount_uploader: изображение, ImageUploader

в ../models/add_images_to_step.rb

изменение четкости store_dir в

«# { Rails.root}/public/uploads/"

в ../app/uploaders/image_uploader.rb

и

"<% = IMAGE_TAG i.image_url.to_s%>"

прав для показа зрения ,

 Смежные вопросы

  • Нет связанных вопросов^_^