Ruby on rails 4 rails使用锚点渲染动作

Ruby on rails 4 rails使用锚点渲染动作,ruby-on-rails-4,anchor,render,simple-form,Ruby On Rails 4,Anchor,Render,Simple Form,我有一个简单的宝石形式。如果我在浏览器中用锚定标记对url进行数字标注,它将起作用: localhost:3000/contacts/#new_contact #show me the correct form in the page 这是我的控制器: class ContactsController < ApplicationController def index @message = Contact.new() end def create @me

我有一个简单的宝石形式。如果我在浏览器中用锚定标记对url进行数字标注,它将起作用:

localhost:3000/contacts/#new_contact #show me the correct form in the page
这是我的控制器:

class ContactsController < ApplicationController

  def index
    @message = Contact.new()
  end

  def create

    @message = Contact.new(msg_params)
    @message.request = request
    if @message.deliver
      redirect_to contacts_path , flash: { success: 'Ok' }
    else
      render action: :index #how can i render the new_contact anchor??
    end

  rescue   ScriptError
    redirect_to contacts_path , flash: { error: 'spam' }
  end

  private
  def msg_params
    params.require(:contact).permit(:name,:email,:message,:spam)
  end
end
class contacts控制器
这是我的表格:

<%= simple_form_for @message, defaults: { label: false} do |f| %>
    <%= f.input :name %>
    <%= f.input :email %>
    <%= f.input :message, :as => :text,input_html: { rows: 7 } %>

    <div class="hidden">
      <%= f.input :spam, :hint => 'Leave this field blank!' %>
    </div>

    <%= f.button :submit, 'Send', class: 'btn-block btn-success btn-lg' %>

<% end %>

:text,input_html:{rows:7}%>
'将此字段留空!'%>

如何使用渲染方法显示新的联系人锚?

您不能使用
render
修改锚标记。事实上,
render
与URI毫无关系

您可以使用现有链接链接到“/url#anchor”,重定向到那里,或者使用javascript实现相同的效果


如果表单上没有设置锚定本身,您可能还需要添加
:id=>“锚定”

您能澄清这个问题吗?链接
localhost:3000/contacts/#new_contact
之所以有效,是因为您正在路由索引以显示表单。这个链接,
localhost:3000/contacts/#blurp
也可以使用。你能用你的问题来澄清你在寻找什么吗?没有办法通过锚来渲染,但我可以为重定向到做这件事。e、 g.
format.html{redirect_以编辑仪表板\产品\路径(@product,anchor:'translations'),注意:'product translations已成功更新。}
有效,而
format.html{render:edit,anchor:'something}
无效