compare data on ruby
My users have some "Patents开发者_JAVA百科". On it, that's a boolean "Expert" who determine the level.
The user logged in must be able to edit the patents from the other users that he is expert.
The problem is the patent has no reference, only the boolean "Expert" and the name come from (belongs_to) the "Skill" who contain the id and name that can be compared.
For exemple I can check if my logged user is the creator of the "Skill". like this :
<% if @patent.skill.user == @current_user %>
<td><%= link_to 'Edit', edit_patent_path %></td>
<% else %>
<% end %>
I would like to ask : "If the @current_user has "Expert" to true on the "Patent" from the same "Skill" that I want to edit, then show me the link"
I have to begin with :
<% if @patent.skill.name
But not capable to find something that can look about the current_user that didn't hold nothing, only the name and other informations.
Thanks for your help to understand which way I can try
I found a solution : In the patents_controller I look for the patent where the current_user is expert (state = 1).
helper_method :is_expert?
private
def is_expert?
Patent.find(:first, :conditions => {:user_id => @current_user, :skill_id => @patent.skill.id, :state => 1})
end
In the controller I just put the condition
<% if is_expert? %>
<%= link_to 'Edit', edit_patent_path %>
<% end %>
Sorry, I realize the vagueness of the question…
精彩评论