0

ビュー/ホームページに小さな数式を作成したいと思います。基本的に、現在のユーザーがサインインしていて(その部分が正しくなっている)、ユーザーがレジストリを作成したかどうか= TRUEの場合は、これまたはそれを指定する必要があります。

以下のコードは次のとおりです。

 <% if user_signed_in? and?????? %>

 <%= link_to "Show My Registry", current_user.registry %>

 <% else %>

 <%= link_to "Create a new registry", new_registry_path %>

 <% end %>

助けてくれてありがとう。

4

3 に答える 3

2

Registryに属するモデルであると仮定するUserと、<% if user_signed_in? && current_user.registry.exists? %>

于 2012-06-13T20:21:08.203 に答える
0

You might want to nest the two decisions. What happens if the user is not signed in? Do you still want the user be able to create a registry without signing in? Other option would be to consider using a before_filter to ensure user is always signed in before she gets to this decision point in your app.

于 2012-06-13T20:27:03.757 に答える
0

ユーザーとレジストリの関係が確立されていることを前提としています。もしそうなら、あなたはあなたのユーザーコントローラーで次のようなメソッドを作成することができます。

def user_registry
  User.current.registry
end

次に、ビューの場合、ifステートメントは次のようになります。

<% if user_signed_in? and user_registry? %>

<%= link_to "Show My Registry", current_user.registry %>

<% else %>

<%= link_to "Create a new registry", new_registry_path %>

<% end %>
于 2012-06-13T20:20:59.887 に答える