【发布时间】:2017-06-28 22:00:56
【问题描述】:
portfolios_controller.rb
class PortfoliosController < ApplicationController
def index
@portfolio_items = Portfolio.all
end
def new
@portfolio_item =Portfolio.new
end
def create
@portfolio_item =Portfolio.new(params.require(:portfolio).permit(:title, :subtitle, :body))
respond_to do |format|
if @portfolio_item.save
format.html { redirect_to portfolios_path, notice: 'Your Portfolio Item is now live.' }
format.json { render :show, status: :created, location: @blog }
else
format.html { render :new }
format.json { render json: @blog.errors, status: :unprocessable_entity }
end
end
end
def edit
@portfolio_item = Portfolio.find(params[:id])
end
def update
@portfolio_item = Portfolio.find(params[:id])
respond_to do |format|
if @portfolio_item.update(params.require(:portfolio).permit(:title, :subtitle, :body))
format.html { redirect_to portfolios_path, notice: 'The record successfully updated.' }
else
format.html { render :edit }
end
end
end
end
def show
@portfolio_item = Portfolio.find(params[:id])
end
show.html.erb
<%= image_tag @portfolio_item.main_image %>
<h1><%= @portfolio_item.title %></h1>
<em><%= @portfolio_item.subtitle %></em>
<p><%= @portfolio_item.body %></p>
【问题讨论】:
-
请发布您的
Portfolio模型。 -
欢迎来到 SO,尝试提供有关您的问题的所有信息(在这种情况下,完整的错误消息会有所帮助)。
-
我修正了您的缩进,这表明您的
show操作不在课程范围内。您需要解决该问题,然后查看问题是否仍然存在。
标签: ruby-on-rails ruby methods