Thorsten wrote:
i guess you have added a RESTful route for this?
map.resource :programs
Well no I haven’t done anything like that. It is a basic rails app
generated with scaffold. Should I post here some configuration file to
help clarifying the issue?
To the main scaffold I have added a new add_comment.html.erb
I try to open that one from the index.html.erb
This is my controller. I have some basic authentication also in place
but that should be ok and is working.
class ProgramsController < ApplicationController
before_filter :check_auth, :except => :index
def add_comment()
@program_id = params[:program_id]
@user = User.find(session[:uid])
end
def secret
puts session[:uid]
@user = User.find(session[:uid])
puts @user.username
redirect_to :action => ‘list’
end
def log_out
session[:uid] = nil
redirect_to :controller => ‘main’
end
GET /programs
GET /programs.xml
def index
@isLogged = false
if session[:uid]
@user = User.find(session[:uid])
@isLogged = true
@username = @user.username
end
@programs = Program.find(:all)
@multiplier = -25
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @programs }
end
end
GET /programs/1
GET /programs/1.xml
def show
@program = Program.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @program }
end
end
GET /programs/new
GET /programs/new.xml
def new
@program = Program.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @program }
end
end
GET /programs/1/edit
def edit
@program = Program.find(params[:id])
end
POST /programs
POST /programs.xml
def create
@program = Program.new(params[:program])
respond_to do |format|
if @program.save
flash[:notice] = 'Program was successfully created.'
format.html { redirect_to(@program) }
format.xml { render :xml => @program, :status => :created,
:location => @program }
else
format.html { render :action => “new” }
format.xml { render :xml => @program.errors, :status =>
:unprocessable_entity }
end
end
end
PUT /programs/1
PUT /programs/1.xml
def update
@program = Program.find(params[:id])
respond_to do |format|
if @program.update_attributes(params[:program])
flash[:notice] = 'Program was successfully updated.'
format.html { redirect_to(@program) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @program.errors, :status =>
:unprocessable_entity }
end
end
end
DELETE /programs/1
DELETE /programs/1.xml
def destroy
@program = Program.find(params[:id])
@program.destroy
respond_to do |format|
format.html { redirect_to(programs_url) }
format.xml { head :ok }
end
end
private
def check_auth
unless session[:uid]
flash[:error] = ‘You need to be logged in to access this panel’
redirect_to :controller => ‘main’
#redirect_to :action => ‘list’
end
end
end
Thanks.