mardi 17 mars 2015

routes error in rails

I am working on a project. I am making an application where a user can add an issue (like a post) and the user can comment on it.


on running this application, I get an error Couldn't find Issue with 'id'=show the code for routes file is



resources :issues do
resources :comments
end

get 'users/new'

get 'users/create'

get 'users/show'

get 'users/edit'

get 'issues/show/:id', :to => 'issues#show'

resources :users
resources :sessions, :only => [:create, :new,:destroy]




get '/signup', :to => 'users#new'
get '/signin' , :to => 'sessions#new'
get '/signout', :to => 'sessions#destroy'


the code for the issues controller is



class IssuesController < ApplicationController


def new
@issue = Issue.new
end


def create
@issue = Issue.new(issues_params)
if @issue.save
flash[:success]='your issue has been raised'
redirect_to :controller => 'issues', :action => 'show', :id => @issue.id
else
render 'new'
end

end

def edit
@issue = Issue.find(params[:id])

end

def update
@issue = Issue.find(params[:id])
if @issue.update_attributes(issues_params)
redirect_to :controller => 'issues', :action => 'show', :id => @issue.id
else
render 'edit'
end
end

def index
@issues = Issue.all

end


def show

@issue = Issue.find(params[:id])


end

def destroy
@issue=Issue.find(params[:id])
@issue.destroy
redirect_to :controller => 'issues', :action => 'index'
end








protected
def issues_params
params.require(:issue).permit(:title,:content)
end


end


the code for the comments controller from where I call the show method in issues controller is



class CommentsController < ApplicationController


def create
@issue = Issue.find(params[:issue_id])
@comment = @issue.comments.create(comment_params)

if @comment.save
redirect_to :controller => 'issues', :action => 'show', :id => @issue[:id]
else
render 'new'
end
end





private
def comment_params
params.require(:comment).permit(:content)

end


end

Aucun commentaire:

Enregistrer un commentaire