相信你能帮助我。
我正在尝试为遗留代码(Typo)添加新功能。但似乎在路由方面存在一些问题。
在项目中,路线以以下方式生成:
%w{advanced cache categories comments content profiles feedback general pages
resources sidebar textfilters themes trackbacks users settings tags redirects seo post_types }.each do |i|
match "/admin/#{i}", :to => "admin/#{i}#index", :format => false
match "/admin/#{i}(/:action(/:id))", :to => "admin/#{i}", :action => nil, :id => nil, :format => false
end
我的功能是合并文章。为此,我在
/管理员/内容
控制器:
def merge
#some code here
end
我添加的一部分视图(_form.html.erb):
<% if current_user.admin? and !@article.id.nil?%>
<div class=''>
<h4><%= _("Merge Articles") %></h4>
<%= label_tag :merge_with, 'Article ID' %><%= text_field_tag :merge_with, nil, :size => 20 %>
<%= button_to 'Merge', admin_content_merge_path(:id => @article.id) %>
</div>
<%end%>
此部分由另一个部分(_edit.html.erb)渲染
<%= form_tag(form_action, :id => "#{form_type}_form", :enctype => "multipart/form-data", :class => className) do %>
<%= render :partial => "form" %>
<% end %>
最后,通过视图new.html.erb来渲染_edit.html.erb
<%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %>
问题是如何为上面的控制器操作编写正确的路由,这将允许我呈现包含新合并文章的编辑页面。我写道:
match "/admin/content/merge/:id" => "admin/content#merge",:as => 'admin/content/merge'
耙式路线
输出:
admin_content_merge /admin/content/merge/:id(.:format) {:controller=>"admin/content", :action=>"merge"}
但正如我所看到的,新的或编辑操作正在被调用。
显然,我的路线错了,不是吗?
你能帮我做这个吗。
提前谢谢!
使现代化
最新的
新建html.erb
:
<% @page_heading = _('New article') %>
<%= render "admin/shared/edit", { :form_type => "article", :form_action => { :action => "new", :id => @article.id , :class => ('autosave')} } %>
<% if current_user.admin? and !@article.id.nil?%>
<%= form_tag "/admin/content/merge/#{@article.id}" do %>
<h4><%= _("Merge Articles") %></h4>
<%= label_tag :merge_with, 'Article ID' %>:
<%= text_field_tag :merge_with %><br />
<%= submit_tag "Merge" %>
<% end %>
<% end %>