DOH!!  I will have mastered rails when I KNOW where to Capitalize AND
where to put an 's' in or not!  Thanks!!

I worked past this error, was able to get the 'index' showing, but
when I go to the 'show' or 'edit' views, I get an error where the
"Project" index ID is WAY out of bounds (I don't think my dev db has
gone beyond 20 id's):

      ActiveRecord::RecordNotFound in MyprojectsController#show
      Couldn't find Project with ID=36732470 AND (`projects`.user_id =
2)

The user_id is passing fine, but the project ID is corrupted. I've
tweaked my 'Show' definition to be current_user.project.find(params
[:id]), current_user.Project.find(params[:id]),
current_user.Projects.find(params[:id]) but these only result in "No
Method" errors. Also, the "destroy" works fine.

Any thoughts why the index is not getting passed correctly for 'Show'
& 'Edit', but it's fine for the 'destroy'?

Myprojects controller is looking like this:
====================
class MyprojectsController < ApplicationController
  # GET /myprojects
  # GET /myprojects.xml
  def index
    @myprojects = current_user.projects.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @myprojects }
    end
  end

  # GET /myprojects/1
  # GET /myprojects/1.xml
  def show
    @myproject = current_user.projects.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @myprojects }
    end
  end

  # GET /myprojects/new
  # GET /myprojects/new.xml
  def new
    @myproject = Project.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @project }
    end
  end

  # GET /myprojects/1/edit
  def edit
    @myproject = current_user.project.find(params[:id])
  end

  # POST /myprojects
  # POST /myprojects.xml
  def create
    @myproject = Project.new(params[:project])

    respond_to do |format|
      if @project.save
        flash[:notice] = 'Project was successfully created.'
        format.html { redirect_to(@project) }
        format.xml  { render :xml => @project, :status
=> :created, :location => @project }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @project.errors, :status
=> :unprocessable_entity }
      end
    end
  end

  # PUT /myprojects/1
  # PUT /myprojects/1.xml
  def update
    @myproject = current_user.Project.find(params[:id])

    respond_to do |format|
      if @project.update_attributes(params[:project])
        flash[:notice] = 'Project was successfully updated.'
        format.html { redirect_to(@project) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @project.errors, :status
=> :unprocessable_entity }
      end
    end
  end

  # DELETE /myprojects/1
  # DELETE /myprojects/1.xml
  def destroy
    @myproject = current_user.project.find(params[:id])
    @myproject.destroy
    flash[:notice] = 'Project was successfully deleted.'
    respond_to do |format|
      format.html { redirect_to(myprojects_url) }
      format.xml  { head :ok }
    end
  end
end


====================


On Jan 26, 8:50 am, Marnen Laibow-Koser <li...@ruby-forum.com> wrote:
> Jon Cox wrote:
>
> >> --------------------Myprojects controller--------------------
> >> class MyprojectsController < ApplicationController
> >>   def index
> >>     @myprojects = current_user.Project.all   #<-------- 'Project'
> >> reference here is getting an undefined method error
>
> >>     respond_to do |format|
> >>       format.html # index.html.erb
> >>       format.xml  { render :xml => @myprojects }
> >>     end
> >>   end
>
> > Would that not need to read
>
> > @myprojects = current_user.projects.all
>
> Or just current_user.projects , since that already returns a collection.
>
>
>
> > PS i'll be impressed if i'm right being new to rails myself! :)
>
> Then prepare to be impressed.  Good catch!
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> mar...@marnen.org
> --
> Posted viahttp://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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to