I am using this example for uploading files in Ruby on Rails. I have some problems with the uploads/index.html.erb
I have some more variables like:
current_user.id - id of a user how is now online
user_id - user_id in a upload table, so it just like a foreign key, to assign several uploads to one user.
So, I want to list only those uploads, whose user_id corresponds to current_user.id. I try to do it in this line
((({%=file.user_id%}).to_i)==((<%=current_user.id%>).to_i))
Somehow it does not work, as uploads, whose user_id does not correspond to current_user.id, are listed as well.
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
{% if ((({%=file.user_id%}).to_i)==((<%=current_user.id%>).to_i)){ %}
<tr class="template-download fade">
<td class="l">
<a href="{%=file.url%}" download="{%=file.name%}">{%=file.user_id%}</a>
</td>
<td class="k">
<a href="{%=file.url%}" download="{%=file.name%}"><%=current_user.id%></a>
</td>
<td class="name">
<a href="{%=file.url%}" download="{%=file.name%}">{%=file.name%}</a>
</td>
<td class="delete">
<button class="btn btn-mini btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
<i class="icon-trash icon-white"></i>
</button>
<input type="checkbox" name="delete" value="1">
</td>
<td></td>
</tr>
{% } %}
{% } %}
</script>
You can fetch uploads in controller smth. like
@files = Upload.where(:user_id => current_user.id)
or if your User
model has_many :uploads
you can make
@files = current_user.uploads
then in @files variable in views you'll have only uploads corresponding to current_user
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.