我试图在c9 ubuntu设置中使用rails构建博客。当我在优化路线时,我意识到我的浏览器中的网址并没有随着我的操作而改变,尽管一切正常。
可以在浏览器中看到的网址实际上设置为显示所有博客'帖子,它确实如此,但是当我尝试仅点击一个(在这种情况下'我的博客帖子1')时,它会执行操作,但网址仍然相同。
但是,如果我手动输入正确的网址,它也可以。
一切正常,但我的网址不会自动更改,但我必须手动完成。在这个阶段,我可以处理,但我担心以后会遇到问题。这是我第一次使用cloud9环境。 控制器:
class BlogsController < ApplicationController
before_action :set_blog, only: [:show, :edit, :update, :destroy]
# GET /blogs
# GET /blogs.json
def index
@blogs = Blog.all
end
# GET /blogs/1
# GET /blogs/1.json
def show
end
# GET /blogs/new
def new
@blog = Blog.new
end
# GET /blogs/1/edit
def edit
end
# POST /blogs
# POST /blogs.json
def create
@blog = Blog.new(blog_params)
respond_to do |format|
if @blog.save
format.html { redirect_to @blog, notice: 'Blog was successfully created.' }
else
format.html { render :new }
end
end
end
# PATCH/PUT /blogs/1
# PATCH/PUT /blogs/1.json
def update
respond_to do |format|
if @blog.update(blog_params)
format.html { redirect_to @blog, notice: 'Blog was successfully updated.' }
else
format.html { render :edit }
end
end
end
# DELETE /blogs/1
# DELETE /blogs/1.json
def destroy
@blog.destroy
respond_to do |format|
format.html { redirect_to blogs_url, notice: 'Blog was successfully destroyed.' }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_blog
@blog = Blog.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def blog_params
params.require(:blog).permit(:title, :body)
end
end
路线:
Rails.application.routes.draw do
resources :portofolioos, except: [:show]
get 'portofolioo/:id', to: 'portofolioos#show', as: 'portofolioo_show'
get 'about', to: 'pages#about'
get 'contact', to: 'pages#contact'
resources :blogs
root to: 'pages#home'
end
查看只有一个表单。它是非常多的脚手架,我只更改了show page以在url中显示id并添加了friendly_id gem,但它们都没有显示在url中,但它的工作正常。
<p><%= link_to portofolio_item.title, portofolioo_show_path(portofolio_item) %></p>