Register now and start sharing your code snippets.
Showing ActiveRecord error messages from jQuery Ajax actions and scripts
HTML (Rails) posted 3 months ago by christian
The HTML , in a layout file, for example application.html.erb:
1 <div id="error-message" style="display:none"> 2 </div>
The JavaScript, rendered by for example create.js.erb:
1 <% if !@category.valid? %> 2 <% 3 errors = <<ERR 4 <p>Please fix the following errors:</p> 5 <ul> 6 #{@category.errors.collect{|err| "<li>" + err[0] + " " + err[1] + "</li>" } } 7 </ul> 8 ERR 9 %> 10 $('#error-message').html('<%= escape_javascript(errors) %>'); 11 $('#error-message').show(); 12 <% else %> 13 $('#error-message').hide(); 14 <% end %>
ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
HTML (Rails) posted 3 months ago by christian
1 <input name="authenticity_token" value="<%= form_authenticity_token %>" type="hidden" />
or
1 <%= token_tag %>
Valid RSS 2.0 Feed Template for Rails
HTML (Rails) posted 10 months ago by christian
Note that because of a bug the pubDate and lastBuildDate tags are displayed in lowercase on this site…
1 <?xml version="1.0"?> 2 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 3 <channel> 4 <atom:link href="http://xxxxxxx" rel="self" type="application/rss+xml" /> 5 <title>Code Snippets - Aktagon</title> 6 <link>http://snippets.aktagon.com/</link> 7 <description>Share your code with the world. Allow others to review and comment.</description> 8 <language>en-us</language> 9 <pubDate><%= @snippets[0].created_at.rfc822 %></pubDate> 10 <lastBuildDate><%= @snippets[0].created_at.rfc822 %></lastBuildDate> 11 <docs>http://blogs.law.harvard.edu/tech/rss</docs> 12 <generator>Aktagon Snippets</generator> 13 <% for snippet in @snippets %> 14 <item> 15 <title><![CDATA[<%= snippet.title %>]]></title> 16 <link><%= snippet_url(snippet) %></link> 17 <description><![CDATA[<%= snippet.rendered_body %>]]></description> 18 <pubDate><%= @snippets[0].created_at.rfc822 %></pubDate> 19 <guid><%= snippet_url(snippet) %></guid> 20 <% for tag in snippet.tags%> 21 <category domain="http://snippets.aktagon.com/snippets"><![CDATA[<%= tag.name %>]]></category> 22 <% end%> 23 </item> 24 <% end %> 25 </channel> 26 </rss> 27
We’ll it’s supposed to be valid, but the syntax highlighting seems to process link tag, so it’s not…
Improve page load times by combining JavaScript and CSS files
HTML (Rails) posted about 1 year ago by christian
Add cache => true to combine JavaScript and CSS files and improve page load times.
See changeset 6164 for more information
1 <%= stylesheet_link_tag 'all', :cache => true %> 2 <%= javascript_include_tag :defaults, :cache => true %>