2017-10-24 5 views
0

から単純部分をレンダリングするとき、私は持っている以下の部分patients/_patient_link.html.erbエラー私のRuby on Railsのアプリでは、コンソール

<a class="patient" href="<%= patient_path(patient_link.id) %>"> 
    <span class="name"><%= patient_link.name %></span> 
</a> 

私は次のコードを使用してコンソールから、この部分をレンダリングしようとしている:

include Rails.application.routes.url_helpers 
view = ActionView::Base.new('app/views/patients', {}, ActionController::Base.new) 
output = view.render(file: '_patient_link.html', locals: {patient_link: User.last, current_user: User.last}) 

それはエラー以下の私を返します。

ActionView::Template::Error: wrong number of arguments (given 3, expected 0..1) 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionpack-4.2.8/lib/action_dispatch/routing/url_for.rb:150:in `url_for' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionpack-4.2.8/lib/action_dispatch/routing/route_set.rb:280:in `call' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionpack-4.2.8/lib/action_dispatch/routing/route_set.rb:223:in `call' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionpack-4.2.8/lib/action_dispatch/routing/route_set.rb:345:in `block (2 levels) in define_url_helper' 
    from /home/mateusz/projects/dashboard/app/views/patients/_patient_link.html.erb:1:in `_app_views_patients__patient_link_html_erb__1558238916296672676_82012840' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/template.rb:145:in `block in render' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/activesupport-4.2.8/lib/active_support/notifications.rb:166:in `instrument' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/template.rb:333:in `instrument' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/template.rb:143:in `render' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/activesupport-4.2.8/lib/active_support/notifications.rb:164:in `block in instrument' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/activesupport-4.2.8/lib/active_support/notifications.rb:164:in `instrument' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/template_renderer.rb:52:in `render_template' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/template_renderer.rb:14:in `render' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/renderer.rb:46:in `render_template' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/renderer/renderer.rb:27:in `render' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/actionview-4.2.8/lib/action_view/helpers/rendering_helper.rb:32:in `render' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/haml-4.0.7/lib/haml/helpers/action_view_mods.rb:12:in `render_with_haml' 
    from (irb):5 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/railties-4.2.8/lib/rails/commands/console.rb:110:in `start' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/railties-4.2.8/lib/rails/commands/console.rb:9:in `start' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:68:in `console' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/railties-4.2.8/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
    from /home/mateusz/.rvm/gems/ruby-2.4.1/gems/railties-4.2.8/lib/rails/commands.rb:17:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 

部分の内側このhref属性はcausiですこのエラーはhref="<%= patient_path(patient_link.id) %>"です。どうすれば修正できますか?

+0

それはのように、ここで同じエラーだ:https://github.com/rails/rails/issues/25007 だから、疑いが誤りであります何とかあなたが使用している宝石の一つによって引き起こされます。ジェムセットに互換性のない宝石がありますか? –

+0

これはあなたの質問に答えるものではありませんが、なぜこのような「手動」方法でHTMLを作成していますか? **任意のHTMLを手作りする必要はなく、** 1行**のルビコードからそのHTMLを生成することができます。 –

+0

ブロックを使って、['link_to'](http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to)を使用してください。 –

答えて

0

私はそれが次のコードで動作させることができました:

ApplicationController.new.render_to_string(
    :partial => 'patients/patient_link', 
    :locals => { :patient_link => User.last , current_user: User.first} 
) 
関連する問題