我有一个Profile模型:
has_many :transcripts, dependent: :destroy
accepts_nested_attributes_for :transcripts, allow_destroy: true
Run Code Online (Sandbox Code Playgroud)
所以在我看来app/views/profiles/_form.html.erb,我有以下几点:
<%= f.simple_fields_for :transcripts do |transcript| %>
<%= render 'transcript_fields', f: transcript %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
而app/views/profiles/_transcript_fields.html.erb看起来像这样:
<%= f.file_field :attachment, class: 'col-lg-4 form-control' %>
Run Code Online (Sandbox Code Playgroud)
所以我想做的就是_transcript_fields部分,当profile存在时transcripts,我希望它显示一个文件字段,其中包含附加文件的名称 - 如果他们想要更改附加的文件,他们可以只是点击相同的上传,file_field它将更新该Transcript记录.
我现在有实际的更新操作,但是会发生什么,它只是显示如下字段:
top file_field是现有文件,bottom是反映可以添加的新字段.
我正在SimpleForm 5.0.2与 ActionText 一起使用。
我希望表单的主体字段为多行(比如 10 行),但我不知道如何让它工作。
这是我目前的尝试:
<%= f.rich_text_area :body, class: 'form-control', name: "article-text", input_html: { rows: 10 }, placeholder: "Enter your article body here..." %>
Run Code Online (Sandbox Code Playgroud)
这会生成以下 HTML:
<trix-editor class="form-control" input_html="{:rows=>10}" placeholder="Enter your article body here..." id="article_body" input="article_body_trix_input_article" data-direct-upload-url="http://localhost:3000/rails/active_storage/direct_uploads" data-blob-url-template="http://localhost:3000/rails/active_storage/blobs/:signed_id/:filename" contenteditable="" role="textbox" trix-id="1" toolbar="trix-toolbar-1"></trix-editor>
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
请注意,我还尝试了各种迭代input_html:,包括但不限于:
<%= ... input_html: { 'rows': '10' } ... %>
<%= ... input_html: { rows: "10" } ... %>
Run Code Online (Sandbox Code Playgroud)
一切都无济于事。
我怎样才能让它发挥作用?
基本上我想申请一个bottom-border,但不是在单元格的底部,我希望它在死亡中心.
我如何仅使用CSS和HTML(并且不使用图形)?
因此想象单元格/行的高度为50px,宽度= 100px,我希望该行宽度= 100px,并且行/单元格中的高度为25px.
谢谢.
PS想象一下像字体的交叉功能 - 但是对于一个空的空间(如果这有意义).
我刚刚在Windows 7机器上安装了Rails等.
创建了我的第一个应用程序,我正在尝试转到第一个生成的应用程序,这就是我得到的:
Routing Error
No route matches "/say/hello"
Run Code Online (Sandbox Code Playgroud)
其中说是应用程序名称,hello是第一个视图的名称.
思考?
理想情况下,希望能够轻松拖放要上传的文件.
如果是这样,我在哪里可以找到它?
谢谢.
所以我最近在两个模型(项目和用户)之间创建了一个HABTM关系.
之前,我在项目表中有一个user_id列 - 它就像一个外键.现在有一整个表可以做到这一点.
但是,如何引用具有特定user_id和project_id的项目?
例如,我曾经有一段我的观点看起来像这样:
<div class="field">
<%= f.label :project_id %><br />
<%= collection_select(:stage, :project_id, Project.where(:user_id => current_user), :id, :name) %>
<br />
</div>
Run Code Online (Sandbox Code Playgroud)
但是,我现在如何从数据库中提取相同的信息,而没有HABTM表的模型?新表称为"projects_users".
我的项目模型如下所示:
# == Schema Information
# Schema version: 20101125223049
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255)
# description :string(255)
# notified :boolean
# created_at :datetime
# updated_at :datetime
#
class Project < ActiveRecord::Base
has_and_belongs_to_many :users
has_many :stages, :dependent => :destroy
has_many :uploads
has_many :comments
#before_validation …Run Code Online (Sandbox Code Playgroud) 我决定下载源代码并在本地编译然后运行sudo make install.
但是,当我尝试运行命令'which ImageMagick'时,我没有看到路径返回到命令行.
我试图让ImageMagick和Paperclip(对于Rails 3)很好地一起玩,但是无法正确安装它 - Paperclip似乎不起作用.当我执行以下操作时,我一直从Rails获得的错误has_attached_file :image, :styles => { :thumb => "64x64" }是Image Paperclip::CommandNotFoundError
sudo make install的输出太大了,所以我把它发布在Github上:https://gist.github.com/723339
实现在这里:http://jsfiddle.net/chp8y/1/
如果将鼠标悬停在第一个框#1上,您将看到"添加客户端"更改颜色,但#1不会.如何在不使用JS的情况下实现这一目标?
如果你这样做,.sit-in-the-corner:hover它只会在你将鼠标悬停在1上时起作用.但这不是我想要的.
思考?
我正在尝试使用此插件:http://docs.jquery.com/Plugins/Validation
其中#user_new是我的表单的id,这就是我的代码:
$('#user_new').validate({
rules: {
user[username]: "required",
user[email]: {
required: true,
email: true
}
},
messages: {
user[username]: "Please specify your name",
user[email]: {
required: "We need your email address to contact you",
email: "Your email address must be in the format of name@domain.com"
}
}
})
Run Code Online (Sandbox Code Playgroud)
这些是我的输入字段在呈现页面时的外观(由Rails生成):
<input class="clearField curved" id="user_f_name" name="user[f_name]" size="30" type="text" value="First Name" /><br />
<input class="clearField curved" id="user_l_name" name="user[l_name]" size="30" type="text" value="Last Name" /><br />
<input class="clearField curved" id="user_username" name="user[username]" size="30" type="text" …Run Code Online (Sandbox Code Playgroud) 这是我得到的错误:
ArgumentError in Home#index
Showing /app/views/clients/_form.html.erb where line #6 raised:
You need to supply at least one validation
Extracted source (around line #6):
3: render :partial => "clients/form",
4: :locals => {:client => client}
5: -%>
6: <% client ||= Client.new
7: new_client = client.new_record? %>
8: <%= form_for(client, :html => { :class=>"ajax-form", :id => "client-ajax-form"}, :remote => true, :disable_with => (new_client ? "Adding..." : "Saving...")) do |f| %>
9: <div class="validation-error" style="display:none"></div>
Run Code Online (Sandbox Code Playgroud)
我的客户端模型如下所示:
class Client < ActiveRecord::Base
# the …Run Code Online (Sandbox Code Playgroud) css ×2
html ×2
jquery ×2
simple-form ×2
actiontext ×1
html5 ×1
imagemagick ×1
macos ×1
paperclip ×1
trix ×1
validation ×1