我从本教程制作了博客应用程序: http://guides.rubyonrails.org/getting_started.html
使用Cloud9的开发者环境。制作博客后,我将其推送到Heroku,但发现了一个问题:我的链接不起作用。
当我在应用程序中转到我的错误日志时,这就是我得到的:
Started GET "/articles" for 144.162.213.240 at 2016-02-15 16:41:18 +0000
Cannot render console from 144.162.213.240! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by ArticlesController#index as HTML
Article Load (0.4ms) SELECT "articles".* FROM "articles"
Rendered articles/index.html.erb within layouts/application (153.5ms)
Completed 200 OK in 207ms (Views: 205.5ms | ActiveRecord: 0.4ms)
以下是代码:
APPLICATION_CONTROLLER
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
ARTICLES_CONTROLLER
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find(params[:id])
end
def new
@article = Article.new
end
def edit
@article = Article.find(params[:id])
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
def update
@article = Article.find(params[:id])
if @article.update(article_params)
redirect_to @article
else
render 'edit'
end
end
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
private
def article_params
params.require(:article).permit(:title, :text)
end
end
WECLOME_CONTROLLER
class WelcomeController < ApplicationController
def index
end
end
EDIT.HTML.ERB
<h1>Editing article</h1>
<%= form_for :article, url: article_path(@article), method: :patch do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@article.errors.count, "error") %> prohibited
this article from being saved:
</h2>
<ul>
<% @article.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 %>
<%= link_to 'Back', articles_path %>
INDEX.HTML.ERB
<h1>Janke Chat</h1>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th colspan="3"></th>
</tr>
<% @articles.each do |article| %>
<tr>
<td><%= article.title %></td>
<td><%= article.text %></td>
<td><%= link_to 'SHOW', article_path(article) %></td>
<td><%= link_to 'EDIT', edit_article_path(article) %></td>
<td><%= link_to 'DESTROY', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table><br>
<%= link_to 'POSTS', controller: 'articles' %> |
<%= link_to 'NEW POST', new_article_path %> |
<a href = "https://fathomless-beyond-24190.herokuapp.com">HOME</a>
NEW.HTML.ERB
<%= form_for :article, url: articles_path do |f| %>
<% if @article.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@article.errors.count, "error") %> prohibited
this article from being saved:
</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %><br>
<p><%= msg %></p>
<% 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 %>
<a href = "http://recipemanager-janaaron97.c9users.io">Go back home</a>
SHOW.HTML.ERB
<p>
<strong>Title:</strong>
<%= @article.title %>
</p>
<p>
<strong>Text:</strong>
<%= @article.text %>
</p>
<%= link_to 'POSTS', controller: 'articles' %> |
<%= link_to 'NEW POST', new_article_path %> |
<%= link_to 'EDIT', edit_article_path(@article) %><br><br>
<a href = "http://recipemanager-janaaron97.c9users.io">HOME</a>
另外,这是我网站的链接: https://fathomless-beyond-24190.herokuapp.com
谢谢!