This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= csrf_meta_tag %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book | |
def read | |
puts "reading book..." | |
end | |
def go_to_page(page_no) | |
puts "Going to page #{page_no}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:! irb -r % |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application < Rails::Application | |
config.middleware.use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/ | |
. | |
. | |
. | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Middleware | |
use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/ | |
require ::File.expand_path('../config/environment', __FILE__) | |
run Test3app::Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 %> |