我想生成前缀为#!
字符串的网址,以便使用ajax(sammy.js)加载网页。
我在application_helper.rb
中编写了一个帮助方法:
def method_missing(method, *args, &block)
super(method, *args, &block)
rescue NoMethodError => e
match = method.to_s.match /^sammy_(\w*_path)$/
prepend = '#!'
unless match.nil?
prepend + send(match[1].to_sym, *args, &block)
else
raise e
end
end
它在开发环境中运行良好,但在生产中出错。
ActionView::TemplateError (column_url failed to generate from {:controller=>"columns", :action=>"show", :id=>#<Column id: 2, author_id: 3, parent_id: nil ...>}, expected: {:controller=>"columns", :action=>"show"}, diff: {:id=>#<Column id: 2, author_id: 3, parent_id: nil ...>}) on line #3 of vendor/plugins/theme/app/views/posts/_post_box.html.erb:
1: <article class="postbox <%= 'double' if post_box_counter.zero? %>">
2: <div class="inner">
3: <p class="post-column"><%= link_to column.title, sammy_column_path(column) %></p>
4: <h2><%= link_to post_box.title, sammy_column_post_path(column, post_box) %></h2>
5: <p class="post-author"><a href="#/szerzo/1-fabian-terez"><%= post_box.author.name %></a></p>
6: <%- link_to sammy_column_post_path(column, post_box) do -%>
(eval):17:in `column_path'
app/helpers/application_helper.rb:66:in `send'
app/helpers/application_helper.rb:66:in `method_missing'
vendor/plugins/theme/app/views/posts/_post_box.html.erb:3
vendor/plugins/theme/app/views/columns/show.html.erb:3
app/controllers/index_controller.rb:8:in `index'