首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mercury编辑器(0.9.0)无法保存Rails 3.2.11中的更改

Mercury编辑器(0.9.0)无法保存Rails 3.2.11中的更改
EN

Stack Overflow用户
提问于 2013-01-17 03:32:42
回答 2查看 1.2K关注 0票数 2

我正在将水星添加到一个简单的博客应用程序中,并希望使用最新的版本,但我无法让它保存更新。下面是我的代码:

Gemfile:

代码语言:javascript
复制
gem 'rails', '3.2.11'
gem "thin", "~> 1.3.1"
gem 'mercury-rails'
gem 'paperclip'

group :development do
  gem 'taps'
  gem "nifty-generators"
  gem 'sqlite3'
end

gem 'jquery-rails'

blogs_controller.rb:

代码语言:javascript
复制
  def update
    @blog = Blog.find(params[:id])
    if @blog.update_attributes(params[:blog])
      redirect_to @blog
    else
      render 'edit'
    end
  end

  def mercury_update
    blog = Blog.find(params[:id])
    blog.content         = params[:content][:blogContent][:value]
    blog.save!
    render text: ""
  end

blog.rb:

代码语言:javascript
复制
class Blog < ActiveRecord::Base
  attr_accessible :title, :content, :author
end

routes.rb:

代码语言:javascript
复制
  Mercury::Engine.routes
  mount Mercury::Engine => '/'
  root :to => "pages#home"

  namespace :mercury do
    resources :images
  end

  resources :blogs do
    member { post :mercury_update }
  end

mercury.html.erb

代码语言:javascript
复制
  <body>
    <script type="text/javascript">
      // Set to the url that you want to save any given page to, leave null for default handling.
      var saveUrl = null;

      // Instantiate the PageEditor
      new Mercury.PageEditor(saveUrl, {
        saveStyle:  'form', // 'form', or 'json' (default json)
        saveMethod: null, // 'PUT', or 'POST', (create, vs. update -- default PUT)
        visible:    true  // boolean - if the interface should start visible or not
      });
    </script>
  </body>

blogs/show.html.erb:

代码语言:javascript
复制
 <div id="blogFull" class="rounded-corners-mild">

 <div id="blogTitle">
   <h1 style="font-size:150%; text-align:center; " class="mercury-region" ><%= @blog.title%></h1>
  </div>

  <div data-mercury="full" id="blogContent" class="mercury-region">
    <%= raw @blog.content %>
  </div><br />
  <%= link_to "mercury", "/editor" + "/blogs" + "/#{@blog.id}", :class => 'bestButton',  
          id: "edit_link", data: {save_url: mercury_update_blog_path(@blog)} %>

添加到: mercury.js:

代码语言:javascript
复制
jQuery(window).on('mercury:ready', function() {
        var saveUrl = $("#edit_link").data("save-url");
        Mercury.saveUrl = saveUrl;
});
Mercury.on('saved', function() {
        window.location.href = window.location.href.replace(/\/editor\//i, '/');
});

我还尝试了这个: to mercury.js:

代码语言:javascript
复制
  onload: function() {
    //Mercury.PageEditor.prototype.iframeSrc = function(url) { return '/testing'; }
    Mercury.on('ready', function() {
      var link = $('#mercury_iframe').contents().find('#edit_link');
      Mercury.saveUrl = link.data('save-url');
      link.hide();
    });

    Mercury.on('saved', function() {
      window.location.href = window.location.href.replace(/\/editor\//i, '/');
    });
  }

两种方法都不起作用。两者都让我找到了编辑器,并允许我进行编辑。我还无法保存任何更改。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-17 05:37:55

尝试保存时是否收到错误消息?上面写着什么?如果显示无法保存,但URL正确,则需要检查日志文件。

我在设置正确的saveUrl时遇到了问题,并在mercury.js中添加了以下代码来修复它;

代码语言:javascript
复制
onload: function() {
    Mercury.on('ready', function() {
        var link = $('#mercury_iframe').contents().find('#edit_link');
        console.log("mercury ready ready", link);
        mercuryInstance.saveUrl = link.data('save-url');
        link.hide();
    });

    Mercury.on('saved', function() {
        window.location.href = window.location.href.replace(/\/editor\//i, '/');
    });
}

this thread on RailsCasts里找到的。

编辑:

我在你的代码中注意到了一些其他的东西。您为POST操作创建了一个路由。在mercury.html.erb中,saveMethod默认设置为“PUT”。将saveMethod更改为“POST”。

票数 3
EN

Stack Overflow用户

发布于 2013-02-22 03:17:29

对我来说,"mercuryInstance“并没有使用上面的解决方案,这让我遇到了麻烦。我确实让它与添加到mercury.js末尾的javascript一起工作:

代码语言:javascript
复制
    jQuery(window).on('mercury:ready', function() {
        var link = $('#edit_link');
        Mercury.saveUrl =link.attr('data-save-url');
        link.hide();
    });
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14366307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档