Ruby on Rails Thursday, December 1, 2011

thiagocifani wrote in post #1034560:
> in your path are you sending the project object as params?
>
> 2011/12/1 Vogon Primo <lists@ruby-forum.com>
>
>> >
>> root :to=> 'projects#index'
>> "Ruby on Rails: Talk" group.
>> To post to this group, send email to rubyonrails-talk@googlegroups.com.
>> To unsubscribe from this group, send email to
>> rubyonrails-talk+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/rubyonrails-talk?hl=en.
>>
>>
>
>
> --
> thiagocifani
> http://thiagocifani.wordpress.com/
> twitter.com/thiagocifani
> del.icio.us/thiagocifani
> <http://del.icio.us/thiagocifani>

No, I am not sending the project object as param, perhaps looking at
tickets controller may be useful ?

class TicketsController < ApplicationController

before_filter :find_project, :only=>[:new,:create,:show,:index]

def find_project

begin
@project = Project.find(params[:project_id])
rescue ActiveRecord::RecordNotFound
flash[:error]="The project you were looking for could not be
found"
redirect_to root_path
end

end

private :find_project

#__________________________


def new


@ticket = @project.tickets.build
@title="--New Ticket for #{@project.name}"

end


def create

@ticket = @project.tickets.build(params[:ticket])

if @ticket.save
flash[:success]="Ticket has been created"
redirect_to [@project,@ticket]
else
flash[:error]="Ticket has not been created"
render 'new'
end


end

#___________________________

def index

@tickets = @project.tickets.all
@title="--#{@project.name}--Tickets"

end


# refactor later

def show
begin
@ticket = @project.tickets.find(params[:id])
rescue ActiveRecord::RecordNotFound

flash[:error]="The ticket you were looking for could not be
found"
redirect_to @project
return
end

@title="--#{@project.name}--Show Ticket--#{@ticket.title}"

end


end

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment