Skip to content

Instantly share code, notes, and snippets.

@andyh
Last active December 31, 2015 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyh/0c28abb7124fb283a924 to your computer and use it in GitHub Desktop.
Save andyh/0c28abb7124fb283a924 to your computer and use it in GitHub Desktop.
remote form example
class KalendarController < ApplicationController
def next
@joke = Joke.find_by(id: rand(1..Joke.count))
end
end
$("#joke_section").html("<%= @joke.content %>")
Kal::Application.routes.draw do
#get "kalendar/show"
root 'kalendar#show'
post "jokes/next", to: "kalendar#next", as: "random_joke"
end
<div>
<blockquote class="pull-left">
<p id="joke_section">
<%= @joke.content %>
</p>
<small><%= @joke.author %> </small>
<%= button_to "Next Joke", random_joke_path, remote: true %>
</blockquote>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment