Ruby on rails Rails carrierwave:未定义的方法`image\uURL';对于#<;短期课程:0x007f9de0204ad8>;
我不熟悉rails。我使用rails 3.2.20和carrierwave gem以两种形式上传图像,即ShorttermCourse和OrientationCourse,效果很好。每当我尝试在短期课程中显示上传的图像时,请使用:Ruby on rails Rails carrierwave:未定义的方法`image\uURL';对于#<;短期课程:0x007f9de0204ad8>;,ruby-on-rails,ruby-on-rails-3,carrierwave,Ruby On Rails,Ruby On Rails 3,Carrierwave,我不熟悉rails。我使用rails 3.2.20和carrierwave gem以两种形式上传图像,即ShorttermCourse和OrientationCourse,效果很好。每当我尝试在短期课程中显示上传的图像时,请使用: <%= image_tag(@shortterm_course.image_url(:thumb).to_s, :class => @shortterm_course.image? ? "img-responsive img-thumbnail" : ni
<%= image_tag(@shortterm_course.image_url(:thumb).to_s, :class => @shortterm_course.image? ? "img-responsive img-thumbnail" : nil) %>
@shortterm\u course.image?“img响应img缩略图”:无)%>
它给出了以下错误:
#短期课程:0x007f9de0204ad8的未定义方法“image_url”
但类似的代码显示了OrientionCourse的图像
当我重新启动rails服务器时,它会显示ShorttermCourse的图像,但随后它会停止DirectionCourse的工作,并给出未定义的方法“image\uURL”错误。以下是短期课程的文件:
show.html.erb:
<!-- row -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Individual Record</h1>
</div>
<!-- /.col-lg-12 -->
<p id="notice"><%= notice %></p>
</div>
<!-- /.row -->
<!-- row -->
<div class="row">
<div class="col-lg-12">
<%= image_tag(@shortterm_course.image_url(:thumb).to_s, :class => @shortterm_course.image? ? "img-responsive img-thumbnail" : nil) %>
<div class="table-responsive">
<table class="table table-striped table-hover">
<tr>
<th>ID</th>
<th>Name</th>
<th>Gender</th>
<th>Religion</th>
<th>Category</th>
<th>Marital status</th>
<th>Email</th>
<th>Stream</th>
<th>College</th>
</tr>
<tr class="success">
<td><%= @shortterm_course.id %></td>
<td><%= @shortterm_course.name %></td>
<td><%= @shortterm_course.gender %></td>
<td><%= @shortterm_course.religion %></td>
<td><%= @shortterm_course.category %></td>
<td><%= @shortterm_course.marital_status %></td>
<td><%= @shortterm_course.email %></td>
<td><%= @shortterm_course.stream %></td>
<td><%= @shortterm_course.college %></td>
</tr>
</table>
<table class="table table-striped table-hover">
<tr>
<th>University</th>
<th>City</th>
<th>District</th>
<th>State</th>
<th>Position</th>
<th>Payscale</th>
<th>Subject</th>
<th>Std Code</th>
<th>Landline</th>
</tr>
<tr class="success">
<td><%= @shortterm_course.university %></td>
<td><%= @shortterm_course.city %></td>
<td><%= @shortterm_course.district %></td>
<td><%= @shortterm_course.state %></td>
<td><%= @shortterm_course.position %></td>
<td><%= @shortterm_course.payscale %></td>
<td><%= @shortterm_course.subject %></td>
<td><%= @shortterm_course.std_code %></td>
<td><%= @shortterm_course.landline %></td>
</tr>
</table>
<table class="table table-striped table-hover">
<tr>
<th>Mobile</th>
<th>University pin</th>
<th>Dob</th>
<th>Date of joining</th>
<th>Preferred date1</th>
<th>Preferred date2</th>
<th>Residential address</th>
<th>Pin</th>
<th>Phd</th>
</tr>
<tr class="success">
<td><%= @shortterm_course.mobile %></td>
<td><%= @shortterm_course.university_pin %></td>
<td><%= @shortterm_course.dob %></td>
<td><%= @shortterm_course.date_of_joining %></td>
<td><%= @shortterm_course.pref_date1 %></td>
<td><%= @shortterm_course.pref_date2 %></td>
<td><%= @shortterm_course.res_address %></td>
<td><%= @shortterm_course.pin %></td>
<td><%= @shortterm_course.phd %></td>
</tr>
</table>
</div>
<!-- /.table-responsive -->
<%= link_to 'Edit', edit_shortterm_course_path(@shortterm_course), :class => 'btn btn-default' %>
<%= link_to 'Delete', shortterm_course_path, method: :delete, :class => 'btn btn-default', data: { confirm: 'Are you sure?' } %>
<%= link_to 'Back', shortterm_record_path, :class => 'btn btn-default' %>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /. row -->
个人记录
@短期课程图片?“img响应img缩略图”:无)%>
身份证件
名称
性别
宗教
类别
婚姻状况
电子邮件
流动
学院
大学
城市
地区
陈述
位置
工资表
主题
标准代码
固定电话
可移动的
大学别针
多巴哥
加入日期
首选日期1
首选日期2
居住地址
别针
博士
“btn btn默认值”%>
“btn btn default”,数据:{确认:'确定吗?}%>
“btn btn默认值”%>
短期课程\u controller.rb
class ShorttermCoursesController < ApplicationController
before_filter :authenticate_admin!, :only => [:show, :edit, :update, :destroy, :record]
layout "adminDashboard", :only => [:show, :edit, :update, :destroy, :record]
# GET /shortterm_courses
# GET /shortterm_courses.json
def index
raise ActionController::RoutingError.new('Not Found')
end
# GET /shortterm_courses/1
# GET /shortterm_courses/1.json
def show
@shortterm_course = ShorttermCourse.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @shortterm_course }
end
end
#List of record
def record
@shortterm_courses = Kaminari.paginate_array(ShorttermCourse.all).page(params[:page]).per(4)
respond_to do |format|
format.html
format.json { render json: @shortterm_courses }
end
end
# GET /shortterm_courses/new
# GET /shortterm_courses/new.json
def new
@shortterm_course = ShorttermCourse.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @shortterm_course }
end
end
# GET /shortterm_courses/1/edit
def edit
@shortterm_course = ShorttermCourse.find(params[:id])
end
# POST /shortterm_courses
# POST /shortterm_courses.json
def create
@shortterm_course = ShorttermCourse.new(params[:shortterm_course])
respond_to do |format|
if @shortterm_course.save
format.html { redirect_to registered_path }
format.json { render json: @shortterm_course, status: :created, location: @shortterm_course }
else
format.html { render action: "new" }
format.json { render json: @shortterm_course.errors, status: :unprocessable_entity }
end
end
end
# PUT /shortterm_courses/1
# PUT /shortterm_courses/1.json
def update
@shortterm_course = ShorttermCourse.find(params[:id])
respond_to do |format|
if @shortterm_course.update_attributes(params[:shortterm_course])
format.html { redirect_to @shortterm_course, notice: 'Shortterm course was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @shortterm_course.errors, status: :unprocessable_entity }
end
end
end
# DELETE /shortterm_courses/1
# DELETE /shortterm_courses/1.json
def destroy
@shortterm_course = ShorttermCourse.find(params[:id])
@shortterm_course.destroy
respond_to do |format|
format.html { redirect_to shortterm_record_path}
format.json { head :no_content }
end
end
end
class ShorttermCourse < ActiveRecord::Base
belongs_to :course
attr_accessible :category, :city, :college, :subject, :date_of_joining, :district, :dob, :email, :gender, :landline, :marital_status, :mobile, :name, :payscale, :phd, :pin, :position, :pref_date1, :pref_date2, :religion, :res_address, :state, :stream, :university, :university_pin, :std_code, :alternate_email, :image, :course_id
mount_uploader :image, ImageUploader
end
class短期课程控制器[:显示,:编辑,:更新,:销毁,:记录]
布局“adminDashboard”,:only=>[:显示,:编辑,:更新,:销毁,:记录]
#获取/短期课程
#GET/shortterm_courses.json
def索引
raise ActionController::RoutingError.new('未找到')
结束
#获取/短期课程/1
#获取/短期课程/1.json
def秀
@短期课程=短期课程.find(参数[:id])
回应待办事项|格式|
format.html#show.html.erb
format.json{render json:@shortterm_course}
结束
结束
#记录清单
def记录
@短期课程=Kaminari.paginate_数组(ShorttermCourse.all).page(参数[:page]).per(4)
回应待办事项|格式|
format.html
format.json{render json:@shortterm_courses}
结束
结束
#获取/短期课程/新课程
#获取/短期课程/new.json
def新
@短期课程=短期课程.new
回应待办事项|格式|
format.html#new.html.erb
format.json{render json:@shortterm_course}
结束
结束
#获取/短期课程/1/编辑
定义编辑
@短期课程=短期课程.find(参数[:id])
结束
#后期/短期课程
#POST/Short-Term_courses.json
def创建
@短期课程=短期课程。新建(参数[:短期课程])
回应待办事项|格式|
如果@shortterm\u course.save
format.html{重定向到注册路径}
format.json{render json:@shortterm_course,status::created,location:@shortterm_course}
其他的
format.html{呈现操作:“新建”}
format.json{render json:@shortterm_course.errors,status::unprocessable_entity}
结束
结束
结束
#PUT/短期课程/1
#PUT/短期课程/1.json
def更新
@短期课程=短期课程.find(参数[:id])
回应待办事项|格式|
如果@shortterm\u course.update\u属性(参数[:shortterm\u course])
format.html{将_重定向到@shortterm_课程,注意:'短期课程已成功更新。}
format.json{head:否