2016-11-12 14 views
0

私はdeviseを使用していますが、私のリンクのパスは私のレールのアプリケーションでは機能しません。なぜですか:/私がクリックすると、 'show'メソッドが呼び出されます。私はこの問題を見据えて少し時間を割いた。リンクパスが破損しています

私はindex.html.erbファイルに問題があると考えています。見てください:)私は、 'ピン'という言葉がshowメソッドを呼び出すように '破壊'へのリンクをたどるべきではないことを理解していますが、代わりに何を入れるべきかはわかりません。

Index.html.erb:

<div id="pins"> 
<% @pins.each do |pin| %> 
     <div class="box"> 
     <%= image_tag pin.image.url %> 
     <%= pin.description %> 
     <%= pin.user.email if pin.user %> 
     <%= link_to 'Show', pin %> 
     <% if pin.user == current_user %> 
     <%= link_to 'Edit', edit_pin_path(pin) %> 
     <%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure more than anything!?' } %></td> 
     <% end %> 
     </div> 
    <% end %> 
</div> 

Pins_controller.rb:

class PinsController < ApplicationController 
    before_action :authenticate_user!, except: [:index, :show] 
    before_action :correct_user, only: [:edit, :update, :destroy] 
    before_action :set_pin, only: [:show, :edit, :update, :destroy] 




    def index 
    @pins = Pin.all 
    end 


    def show 
    @pin = Pin.find params[:id] 
    end 


    def new 
    @pin = Pin.new 
    end 


    def edit 
    end 

    def create 
    @pin = Pin.new(pin_params) 
    if @pin.save 
     redirect_to @pin, notice: 'Pin was successfully created.' 
    else 
     render action: 'new' 
    end 
    end 




    def update 
     if @pin.update(pin_params) 
     redirect_to @pin, notice: 'Pin was successfully updated.' 
     else 
     render action: 'edit' 
     end 
    end 




    def destroy 
    @pin.destroy 
    redirect_to pins_url 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_pin 
     @pin = Pin.find(params[:id]) 
    end 

    def correct_user 
    @pin = current_user.pins.find(params[:id]) 
    redirect_to pins_path, notice: "Not allowed!" if @pin.nil? 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
def pin_params 
     params.require(:pin).permit(:description, :image) 
end 
end 

そして、私のroutes.rbをファイル

Rails.application.routes.draw do 
    resources :pins 
    devise_for :users 
    root "pages#home" 

    get "about" => "pages#about" 

end 
+1

リンクをクリックすると確認メッセージが表示されますか?そうでなければ、rails-ujsライブラリがあなたのページで有効になっていないことを意味します。 – MikDiet

+0

ああ、そうではありません。私はそれを今感謝します:) – Benjamints

答えて

0

私の問題は、「私は表示されませんでしたということでした私のapplication.jsのjquery '

私の問題を解決した挿入。

関連する問題