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
r1 = Role.create({name: "Regular", description: "Can read items"}) | |
r2 = Role.create({name: "Seller", description: "Can read and create items. Can update and destroy own items"}) | |
r3 = Role.create({name: "Admin", description: "Can perform any CRUD operation on any resource"}) | |
u1 = User.create({name: "Sally", email: "[email protected]", password: "aaaaaaaa", password_confirmation: "aaaaaaaa", role_id: r1.id}) | |
u2 = User.create({name: "Sue", email: "[email protected]", password: "aaaaaaaa", password_confirmation: "aaaaaaaa", role_id: r2.id}) | |
u3 = User.create({name: "Kev", email: "[email protected]", password: "aaaaaaaa", password_confirmation: "aaaaaaaa", role_id: r2.id}) | |
u4 = User.create({name: "Jack", email: "[email protected]", password: "aaaaaaaa", password_confirmation: "aaaaaaaa", role_id: r3.id}) | |
i1 = Item.create({name: "Rayban Sunglasses", description: "Stylish shades", price: 99.99, user_id: u2.id}) |
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
<% if user_signed_in? %> | |
Signed in as <%= current_user.email %>. Not you? | |
<%= link_to "Edit profile", edit_user_registration_path %> | |
<%= link_to "Sign out", destroy_user_session_path, :method => :delete %> | |
<% else %> | |
<%= link_to "Sign up", new_user_registration_path %> or <%= link_to "sign in", new_user_session_path %> | |
<% end %> | |
<% flash.each do |name, msg| %> | |
<%= content_tag :div, msg, id: "flash_#{name}" %> |
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
rails new store | |
cd store | |
rails g scaffold user name:string role:belongs_to | |
rails g scaffold role name:string description:string | |
rails g scaffold item name:string description:text 'price:decimal{5,2}', user:belongs_to | |
rake db:migrate |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>AJAX demo</title> | |
</head> | |
<body> | |
<input type="text" id="myTextField" /> | |
<button id="ajax">Submit AJAX request</button> |
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
#encoding: UTF-8 | |
start_path = "/path/to/parent/directory/" | |
def change_text_file(path) | |
file_contents = "" | |
File.open(path,'r') do |file| | |
while line = file.gets | |
if line.force_encoding("ISO-8859-1").encode("utf-8", replace: nil).match "whatever" | |
line = line.sub("whatever", "new whatever") | |
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
start_path = "/path/to/parent/directory/" | |
def change_text_file(path) | |
file_contents = "" | |
File.open(path,'r') do |file| | |
while line = file.gets | |
if line.match "whatever" | |
line = line.sub("whatever", "new whatever") | |
end | |
file_contents += line |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<style> | |
#overlay{ | |
position: fixed; | |
top: 0%; | |
left: 0%; | |
width: 100%; |
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
require 'fox16' | |
include Fox | |
class MyApp < FXMainWindow | |
def initialize(app) | |
@app = app | |
super(app, "Test", :height => 150, :width => 350, :opts=> DECOR_ALL) | |
self.connect(SEL_CLOSE, method(:on_close)) | |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Persist checkboxes</title> | |
<style> | |
button{ | |
margin-top:8px; | |
} | |
</style> |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>AJAX filter demo</title> | |
<style> | |
body { | |
padding: 10px; | |
} |