Search code examples
ruby-on-railsruby-on-rails-3.1erbcappuccino

Integrating Cappuccino with Ruby on Rails


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)


Solution

  • 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