删除操作似乎在rails 3.2.1中不起作用

时间:2014-07-02 23:03:08

标签: javascript ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我有这个问题。我正在Ruby on Rails 3.2.1上做一个程序 我用脚手架

 1)rails generate scaffold Article name:string description:text
 2)rake db:migrate
 3)rails server

当我点击破坏时,javascript卡特尔没有出现,页面被定向到show方法 你能救我吗?

本地主机:3000 /制品

Listing articles

Title   Body            
Prueba numero 1 esta articula crea el articulo 1    Show    Edit    Destroy
titulo 2    este es el titulo 2                     Show    Edit    Destroy

New Article

要点击Destroy,Javascript卡特尔没有出现,页面被重定向到

本地主机:3000 /物品/ 1

Title: Prueba numero 1

Body: esta articula crea el articulo 1

Edit | Back

文章控制器

class ArticlesController < ApplicationController   # GET /articles   #

GET /articles.json   
def index
     @articles = Article.all

     respond_to do |format|
       format.html # index.html.erb
       format.json { render json: @articles }
     end   
   end

   # GET /articles/1   # GET /articles/1.json  
 def show
     @article = Article.find(params[:id])

     respond_to do |format|
       format.html # show.html.erb
       format.json { render json: @article }
     end   
   end

   # GET /articles/new   # GET /articles/new.json  
 def new
     @article = Article.new

     respond_to do |format|
       format.html # new.html.erb
       format.json { render json: @article }
     end   
  end

   # GET /articles/1/edit   
  def edit
     @article = Article.find(params[:id])  
  end

   # POST /articles   # POST /articles.json   
  def create
     @article = Article.new(params[:article])

     respond_to do |format|
       if @article.save
         format.html { redirect_to @article, notice: 'Article was successfully created.' }
         format.json { render json: @article, status: :created, location: @article }
       else
         format.html { render action: "new" }
         format.json { render json: @article.errors, status: :unprocessable_entity }
       end
     end   
    end

   # PUT /articles/1   # PUT /articles/1.json   
   def update
     @article = Article.find(params[:id])

     respond_to do |format|
       if @article.update_attributes(params[:article])
         format.html { redirect_to @article, notice: 'Article was successfully updated.' }
         format.json { head :no_content }
       else
         format.html { render action: "edit" }
         format.json { render json: @article.errors, status: :unprocessable_entity }
       end
     end   
   end

   # DELETE /articles/1   # DELETE /articles/1.json   
   def destroy
     @article = Article.find(params[:id])
     @article.destroy

     respond_to do |format|
       format.html { redirect_to articles_url }
       format.json { head :no_content }
     end   
    end 
  end

这是文件index.html.erb

    <h1>Listing articles</h1>

    <table>
      <tr>
        <th>Title</th>
        <th>Body</th>
        <th></th>
        <th></th>
        <th></th>
      </tr>

    <% @articles.each do |article| %>
      <tr>
        <td><%= article.title %></td>
        <td><%= article.body %></td>
        <td><%= link_to 'Show', article %></td>
        <td><%= link_to 'Edit', edit_article_path(article) %></td>
        <td><%= link_to 'Destroy', article, confirm: 'Are you sure?', method: :delete %></td>

      </tr>
    <% end %>
    </table>

    <br />

    <%= link_to 'New Article', new_article_path %>

 application.html.erb Layout

    <!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>

0 个答案:

没有答案