相关疑难解决方法(0)

为什么Rails 4.2 +响应者一直告诉我向Gemfile添加响应者?

我正在将Rails 4.1.8应用程序(也使用rails-api~> 0.3.1)升级到4.2.0.rc2,并希望保留该respond_with功能.我已添加responders到Gemfile中,但是当我bin/rake spec,我得到:

/Users/sloveless/.gem/ruby/2.1.0/gems/actionpack-4.2.0.rc2/lib/action_controller/metal/mime_responds.rb:10:in `respond_to': The controller-level `respond_to' feature has been extracted to the `responders` gem. Add it to your Gemfile to continue using this feature: (NoMethodError)
  gem 'responders', '~> 2.0'
Consult the Rails upgrade guide for details.
    from /Users/sloveless/Development/twilight/app/controllers/application_controller.rb:6:in `<class:ApplicationController>'
    from /Users/sloveless/Development/twilight/app/controllers/application_controller.rb:1:in `<top (required)>'
    from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:274:in `require'
    from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:274:in `require'
    from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:360:in `require_or_load'
    from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:494:in `load_missing_constant'
    from /Users/sloveless/.gem/ruby/2.1.0/gems/activesupport-4.2.0.rc2/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/sloveless/Development/twilight/app/controllers/zone_maps_controller.rb:1:in `<top (required)>'
    from …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-4.2

7
推荐指数
1
解决办法
8345
查看次数

如何在使用AJAX单击link_to后在同一页面上呈现部分

我有一份客户名单.每个客户都有一个链接,链接到客户页面并显示他的数据.

我想链接到客户表下方同一页面上的部分呈现.在使用表初始化"页面"时,应加载带有"选择客户"之类的空白页面.

我的客户列表代码:

<h1>Listing Customers</h1>

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th colspan="3">Actions</th>
    </tr>
  </thead>

  <tbody>
    <% @customers.each do |customer| %>
      <tr>
        <td><%= customer.name %></td>
        <td><%= link_to 'Show', customer %></td>
        <td><%= link_to 'Edit', edit_customer_path(customer) %></td>
        <td><%= link_to 'Destroy', customer, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>

  </tbody>
</table>

<br>

<%= link_to 'New Customer', new_customer_path, class: "button", id: "new_customer" %>
Run Code Online (Sandbox Code Playgroud)

我部分用于展示客户:

<p>
  <strong>Name:</strong>
  <%= @customer.name %>
  <%= @customer.id %>
</p>

<%= link_to 'Edit Customer', edit_customer_path(@customer) %> …
Run Code Online (Sandbox Code Playgroud)

ajax asynchronous ruby-on-rails partial

6
推荐指数
1
解决办法
1万
查看次数

使用带有format.js的AJAX的"ActionController :: UnknownFormat"

我有模特:想法,项目,产品.我想在Idea的编辑视图中通过Items添加产品到Ideas.我的edit.html.erb - 想法

<div id="items">
  <%= render @idea.items %>
</div>

<div class="products">
  <% @products.each do |p| %>
    <%= p.title %><%= button_to '+', items_path(product_id: p.id, idea_id: @idea.id), remote: true %>
  <% end %>
</div>
Run Code Online (Sandbox Code Playgroud)

我的物品控制器:

def create
    product = Product.friendly.find(params[:product_id])
    @item = @idea.add_product(product.id)

    respond_to do |format|
      if @item.save
        format.js 
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

idea.rb

 def add_product(product_id)
         item = items.find_by(product_id: product_id)
         if item
         else
            item = items.build(product_id: product_id)
         end
         item
    end
Run Code Online (Sandbox Code Playgroud)

我的"create.js.erb"

$('#items').html("<%= escape_javascript render(@idea.items) %>");
Run Code Online (Sandbox Code Playgroud)

当我在def create(items_controller)中放入"format.html {redirect_to:back}"时,一切顺利,但没有AJAX =(

日志

已完成406在91ms内无法接受

ActionController …

javascript ruby ajax ruby-on-rails

2
推荐指数
1
解决办法
3093
查看次数