Can i render :partial a view without leading under

2020-05-24 19:53发布

i am facing a precarious condition here. I need to partially render a page that does not have a leading underscore.

<%= render(:partial => "contact" ,:controller=>"home") %>

this will look for

app/views/home/_contact.html.erb

but i want it to look for

app/views/home/contact.html.erb

is there a way of doing this.?

Thanks

3条回答
可以哭但决不认输i
2楼-- · 2020-05-24 20:18

You should not try to bypass the conventions if not really necessary. I guess contact.html.erb contains a form. Put this into app/views/home/_contact.html.erb and render it in app/views/home/contact.html.erb.

Or as fl00r answered:

<%= render :file => '/homes/contact' %>
查看更多
狗以群分
3楼-- · 2020-05-24 20:27

As eteubert points out, one of the strengths of Rails is its opinionated nature. What you are trying to do here is bend that to your will. Don't. If you need to render something in another page as a partial, then you really should follow convention and extract a partial from the original page. If there's a form in that page for example, extract it out into a partial and have the original page render the partial as well.

You'll find the less you try to fight Rails, the easier things become.

查看更多
Deceive 欺骗
4楼-- · 2020-05-24 20:31
<%= render :file => '/homes/contact' %>
查看更多
登录 后发表回答