Skip to content

Instantly share code, notes, and snippets.

View overture8's full-sized avatar

Phil McClure overture8

  • Stora
  • Belfast, Northern Ireland
View GitHub Profile
<%= csrf_meta_tag %>
irb(main):004:0> b = Book.new
irb(main):004:0> b.read
=> "reading book..."
irb(main):004:0> b.go_to_page(101)
=> "Going to page 101"
class Book
def read
puts "reading book..."
end
def go_to_page(page_no)
puts "Going to page #{page_no}"
end
end
class Application < Rails::Application
config.middleware.use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/
.
.
.
end
# Middleware
use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/
require ::File.expand_path('../config/environment', __FILE__)
run Test3app::Application
class CommentsController < ApplicationController
respond_to :html, :xml, :js
def create
post = Post.find(params[:post_id])
@comment = post.comments.build(params[:comment])
if @comment.save
respond_with(@comment)
end
end
$('comments').insert( { bottom: "<%= escape_javascript(render @comment) %>" } ); // Insert the _comment partial at the bottom of the comments list
$$('.comment').last().highlight(); // Highlight the last comment (the one you just inserted!)
$('comment_body').clear(); // Clear the form text area
<div id="comments">
<%= render @post.comments %>
</div>
<% form_for [@post, Comment.new], :remote => true do |f| %>
<%= f.label :body %><br />
<%= f.text_area :body, :rows => 5 %><br />
<%= f.submit %>
<% end %>