当我意识到你应该在视图中使用帮助器时,我需要一个帮助器在我的控制器中,因为我正在构建一个JSON对象来返回.
它有点像这样:
def xxxxx
@comments = Array.new
@c_comments.each do |comment|
@comments << {
:id => comment.id,
:content => html_format(comment.content)
}
end
render :json => @comments
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能访问我的html_format助手?
在看过Ryan优秀的Railcast Simple OmniAuth后,我已经设法在我的应用程序中实现身份验证.
一切都很好,但在我看来,我的链接看起来像这样:
<%= link_to 'Sign in with Twitter', '/signin/twitter' %>
<%= link_to 'Sign in with Facebook', '/signin/facebook' %>
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种优雅的方法来创建一个命名路由来替换它:
<%= link_to 'Sign in with Twitter', signin_twitter_path %>
<%= link_to 'Sign in with Facebook', signin_facebook_path %>
Run Code Online (Sandbox Code Playgroud)
要么:
<%= link_to 'Sign in with Twitter', signin_path(:twitter) %>
<%= link_to 'Sign in with Facebook', signin_path(:facebook) %>
Run Code Online (Sandbox Code Playgroud)
OmniAuth已经处理了这些路线......在我的routes.rb文件中,我只有回调和退出的东西:
match '/signin/:provider/callback' => 'sessions#create'
match '/signout' => 'sessions#destroy', :as => :signout
Run Code Online (Sandbox Code Playgroud)
所以我不知道在哪里可以创建那些命名的路由.
任何帮助将不胜感激.谢谢.