0

I have a Cappuccino app that I am integrating with a Rails backend. A key feature of the app is authentication which is managed entirely by rails. The way I set it up is that the cappuccino js conditionally executes if the user is logged in, like this:

<% if signed_in? %>

<div id="cappuccino-body">
<script type="text/javascript">
document.write("Hello World")
</script>
</div>

 <% end %>

where signed_in? is a rails method that returns a boolean value reflecting whether the user is authenticated.

The issue I am having is two fold, first, I put this script into the show user view, when I drop the cappuccino .j files into app/views/users directory, they are not detected. Where in the rails directory structure do I drop these files in? Is it in public? or in assets?

Second is can I take the embedded ruby conditional statement above, and use it in a separate erb file? (one that isn't associated with any of the standard views but still has access to the rails methods in the backend)

Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83

1 Answers1

0

You should put Cappuccino's JavaScript file(s) into /vendor/assets/javascripts.

/app/assets/javascripts or /public/javascripts would be fine to, but since it's not your application's code /vendor/assets/javascripts is the place to go.

For the second question, I'm not really sure what you want to achieve with such a setup, but using partials may serve you well: http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials

Koraktor
  • 41,357
  • 10
  • 69
  • 99
  • Thanks for the answer, there was no javascripts folder inside /vendor/assets so I created my own but I'm still getting 404 errors when the app tries to run the scripts. – Andrew Lauer Barinov Feb 28 '12 at 18:48
  • Did you run `rake assets:precompile` before starting your server? See http://guides.rubyonrails.org/asset_pipeline.html for more info on Rails 3's assets pipeline. – Koraktor Feb 28 '12 at 22:44