Since you mention :javascript I assume you are using haml to render the view.
Normally you would set @works in the controller, then your view code would be
:javascript
html_data = "#{j render :partial => 'other_portfolio', @works} }";
$("#other_portfolio").html(html_data)
Also note, that if you are using this view in reply to a rails json call (e.g. link_to :remote => true, you should use the :plain tag.
If you really really want to set a variable in your view, that is definitely possible, but not inside the :javascript or :plain tag, but you can use it.
Like so:
- works = all_filter_record
:javascript
html_data = "#{j render :partial => 'other_portfolio', works} }";
$("#other_portfolio").html(html_data)
Note while it is possible to set variables in a view, it is considered bad form to have to much code in views, and setting instance variables even more so (setting an instance variable suggests you are going to use it in more views/partials, but then how will you ever know where the data is set??). So if you need an instance variable: set it in the controller.