我在rails项目中使用ckeditor WYSIWYG text editor。特别是:我在生产模式下配置图像上传时遇到问题。
在开发模式下,它在使用Puma时在生产模式下本地工作。当我点击上传照片并点击Browse Server
按钮时。它会立即查找我期望的照片:/assets/ckeditor_assets/pictures
。
问题是让它在nginx的生产模式下工作。当我在生产模式下使用nginx时:它返回404 Not Found
错误消息。我查看了我的服务器日志,这就是它的内容:
" /无功/网络/ MYAPP / CKEditor的/图片"失败(2:没有这样的文件或目录)
因此,由于某种原因,它试图在我的公共目录中找到ckeditor
目录(因为这是我的公共目录的符号链接)。我甚至不确定为什么ckeditor正在寻找ckeditor
目录,而不应该在我的应用public/assets/ckeditor_assets
目录中查找。
我尝试通过在公共目录中创建ckeditor
目录,然后在其中放置pictures
目录来解决此问题。但是,当我这样做时,我收到403 Forbidden
错误。
我注意到在config/initializers/ckeditor.rb
文件中有这一行:
# Customize ckeditor assets path
# By default: nil
#config.asset_path = "http://www.example.com/assets/ckeditor/"
所以只是为了给它一个镜头我硬编码我想让ckeditor去拍照片,但不幸的是,它也没有用。
任何建议请告诉我。谢谢!我会继续展示我的ckeditor::picture
模型文件,以防提供任何线索:
class Ckeditor::Picture < Ckeditor::Asset
has_attached_file :data,
:url => "/assets/ckeditor_assets/pictures/:id/:style_:basename.:extension",
:path => ":rails_root/public/assets/ckeditor_assets/pictures/:id/:style_:basename.:extension",
:styles => { :content => '800>', :thumb => '118x100#' }
validates_attachment_presence :data
validates_attachment_size :data, :less_than => 2.megabytes
validates_attachment_content_type :data, :content_type => /\Aimage/
def url_content
url(:content)
end
end
答案 0 :(得分:0)
我的一个伙伴想出来了。事实证明,它只是on insert button code
string status = "Y";
//Random random = new Random();
//int randomNumber = random.Next(0, 100);
string random1 = System.Web.Security.Membership.GeneratePassword(10, 0);
string concate = textBox1.Text + "-" + textBox2.Text + "-" + textBox3.Text.Substring(textBox3.Text.Length - 4) + "-" + random1;
string connectionString = null;
connectionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
con.ConnectionString = connectionString;
string SqlString = "Insert Into Registration (Name,Last_Name,Contact_No,Address,Insert_Date,Registration_key,Status) Values (?,?,?,?,?,?,?)";
//using (OleDbCommand cmd = new OleDbCommand(SqlString, con))
//{
OleDbCommand cmd = new OleDbCommand(SqlString, con);
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Name", textBox1.Text);
cmd.Parameters.AddWithValue("@Last_Name", textBox2.Text);
cmd.Parameters.AddWithValue("@Contact_No", textBox3.Text);
cmd.Parameters.AddWithValue("@Address", textBox4.Text);
cmd.Parameters.AddWithValue("@Insert_Date", textBox5.Text);
cmd.Parameters.AddWithValue("@Registration_key", concate);
cmd.Parameters.AddWithValue("@Status", status);
//}
int n = cmd.ExecuteNonQuery();
con.Close();
if (n > 0)
{
MessageBox.Show("Data Inserted Successfully,NOW PLEASE ACTIVATE APPLICATION PUTTING ACTIVATE KEY ", "Data Inserted ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
on update button code --
string Status = "N";
string connectionString = null;
connectionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
con.ConnectionString = connectionString;
string recover = "SELECT Registration_key from Registration where Registration_key='" + textBox6.Text + "'";
OleDbCommand cmd = new OleDbCommand(recover, con);
con.Open();
OleDbDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
textBox6.Text = reader["Registration_key"].ToString();
if (con.State == ConnectionState.Open)
{
con.Close();
}
string cmd1 = "update Registration set Status=@Status where Registration_key=@Registration_key";
cmd = new OleDbCommand(cmd1, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Status", Status);
cmd.Parameters.AddWithValue("@Registration_key", textBox6.Text);
con.Open();
int n2 = cmd.ExecuteNonQuery();
con.Close();
this.Hide();
Login_Page lp = new Login_Page();
lp.Show();
}
else
{
MessageBox.Show("Invalid Activated Key", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
con.Close();
on load event--
string connectionString = null;
connectionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
con.ConnectionString = connectionString;
string Comparing="N";
string query = "select Status from Registration where Status='N'";
con.Open();
OleDbCommand cmd = new OleDbCommand(query, con);
string compare = Convert.ToString(cmd.ExecuteScalar());
con.Close();
if (compare == Comparing)
{
this.Hide();
Login_Page lp = new Login_Page();
lp.Show();
}
else if (compare != Comparing)
{
Registration_Form rf = new Registration_Form();
rf.Show();
}
文件中所需的配置。我使用的是nginx和乘客。
ck_editor向nginx.conf
发送请求,而不是ckeditor/pictures
。基本上:它忽略了应用程序的相对路径(通过乘客)。我刚才更新了位置块正则表达式:
MYAPP/ckeditor/pictures
另一种方法是,可以通过覆盖the ckeditor config.js file中的某些配置来放弃位置块中# nginx.conf
...
location ~ ^/(RELATIVE_PATH_FOR_APP|ckeditor/pictures)(/.*|$) {
...
}
的正则表达式。这样您就可以在应用程序级别指定ck_editor路由,而不是服务器级别。