diff options
Diffstat (limited to 'guides/code/getting_started/app/views')
9 files changed, 120 insertions, 0 deletions
diff --git a/guides/code/getting_started/app/views/comments/_comment.html.erb b/guides/code/getting_started/app/views/comments/_comment.html.erb new file mode 100644 index 0000000000..3d2bc1590e --- /dev/null +++ b/guides/code/getting_started/app/views/comments/_comment.html.erb @@ -0,0 +1,15 @@ +<p> + <strong>Commenter:</strong> + <%= comment.commenter %> +</p> + +<p> + <strong>Comment:</strong> + <%= comment.body %> +</p> + +<p> + <%= link_to 'Destroy Comment', [comment.post, comment], + :method => :delete, + :data => { :confirm => 'Are you sure?' } %> +</p> diff --git a/guides/code/getting_started/app/views/comments/_form.html.erb b/guides/code/getting_started/app/views/comments/_form.html.erb new file mode 100644 index 0000000000..00cb3a08f0 --- /dev/null +++ b/guides/code/getting_started/app/views/comments/_form.html.erb @@ -0,0 +1,13 @@ +<%= form_for([@post, @post.comments.build]) do |f| %> + <p> + <%= f.label :commenter %><br /> + <%= f.text_field :commenter %> + </p> + <p> + <%= f.label :body %><br /> + <%= f.text_area :body %> + </p> + <p> + <%= f.submit %> + </p> +<% end %> diff --git a/guides/code/getting_started/app/views/layouts/application.html.erb b/guides/code/getting_started/app/views/layouts/application.html.erb new file mode 100644 index 0000000000..6578a41da2 --- /dev/null +++ b/guides/code/getting_started/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> +<head> + <title>Blog</title> + <%= stylesheet_link_tag "application", :media => "all" %> + <%= javascript_include_tag "application" %> + <%= csrf_meta_tags %> +</head> +<body> + +<%= yield %> + +</body> +</html> diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb new file mode 100644 index 0000000000..f22139938c --- /dev/null +++ b/guides/code/getting_started/app/views/posts/_form.html.erb @@ -0,0 +1,25 @@ +<%= form_for @post do |f| %> + <% if @post.errors.any? %> + <div id="errorExplanation"> + <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> + <ul> + <% @post.errors.full_messages.each do |msg| %> + <li><%= msg %></li> + <% end %> + </ul> + </div> + <% end %> + <p> + <%= f.label :title %><br /> + <%= f.text_field :title %> + </p> + + <p> + <%= f.label :text %><br /> + <%= f.text_area :text %> + </p> + + <p> + <%= f.submit %> + </p> +<% end %> diff --git a/guides/code/getting_started/app/views/posts/edit.html.erb b/guides/code/getting_started/app/views/posts/edit.html.erb new file mode 100644 index 0000000000..911a48569d --- /dev/null +++ b/guides/code/getting_started/app/views/posts/edit.html.erb @@ -0,0 +1,5 @@ +<h1>Editing post</h1> + +<%= render 'form' %> + +<%= link_to 'Back', :action => :index %> diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb new file mode 100644 index 0000000000..9a0e90eadc --- /dev/null +++ b/guides/code/getting_started/app/views/posts/index.html.erb @@ -0,0 +1,23 @@ +<h1>Listing posts</h1> + +<%= link_to 'New post', :action => :new %> + +<table> + <tr> + <th>Title</th> + <th>Text</th> + <th></th> + <th></th> + <th></th> + </tr> + +<% @posts.each do |post| %> + <tr> + <td><%= post.title %></td> + <td><%= post.text %></td> + <td><%= link_to 'Show', :action => :show, :id => post.id %> + <td><%= link_to 'Edit', :action => :edit, :id => post.id %> + <td><%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :data => { :confirm => 'Are you sure?' } %> + </tr> +<% end %> +</table> diff --git a/guides/code/getting_started/app/views/posts/new.html.erb b/guides/code/getting_started/app/views/posts/new.html.erb new file mode 100644 index 0000000000..ce9523a721 --- /dev/null +++ b/guides/code/getting_started/app/views/posts/new.html.erb @@ -0,0 +1,5 @@ +<h1>New post</h1> + +<%= render 'form' %> + +<%= link_to 'Back', :action => :index %> diff --git a/guides/code/getting_started/app/views/posts/show.html.erb b/guides/code/getting_started/app/views/posts/show.html.erb new file mode 100644 index 0000000000..65809033ed --- /dev/null +++ b/guides/code/getting_started/app/views/posts/show.html.erb @@ -0,0 +1,18 @@ +<p> + <strong>Title:</strong> + <%= @post.title %> +</p> + +<p> + <strong>Text:</strong> + <%= @post.text %> +</p> + +<h2>Comments</h2> +<%= render @post.comments %> + +<h2>Add a comment:</h2> +<%= render "comments/form" %> + +<%= link_to 'Edit Post', edit_post_path(@post) %> | +<%= link_to 'Back to Posts', posts_path %> diff --git a/guides/code/getting_started/app/views/welcome/index.html.erb b/guides/code/getting_started/app/views/welcome/index.html.erb new file mode 100644 index 0000000000..e04680ea7e --- /dev/null +++ b/guides/code/getting_started/app/views/welcome/index.html.erb @@ -0,0 +1,2 @@ +<h1>Hello, Rails!</h1> +<%= link_to "My Blog", :controller => "posts" %> |