SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    Houston, Texas, USA
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Resource Routing Frustration

    I am having problems with Resource routing.

    I generated a new resource called Page using the generate scaffold command.

    When I go to the http://0.0.0.0:3000/pages/new , enter data, then press Submit, the page is routed back to the list page: http://0.0.0.0:3000/pages

    I have another resource called Announcement that was created the same way and it does add a record, then routes to the view page.

    This is happening on Rails 2.1, on a PC using InstantRails, AND now on a Mac.

    Is anyone else having this issue?

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    Houston, Texas, USA
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a little more information....


    I used this command to create the restful resource:

    script/generate scaffold page title:string content:text enabled:boolean

    ------------------------------------------------

    The following line got added to routes.rb file

    map.resources pages

    ------------------------------------------------

    The controller looks like this... no changes were made to the one generated

    class PagesController < ApplicationController
    # GET /pages
    # GET /pages.xml
    def index
    @pages = Page.find_all)

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

    # GET /pages/1
    # GET /pages/1.xml
    def show
    @page = Page.find(params[:id])

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

    # GET /pages/new
    # GET /pages/new.xml
    def new
    @page = Page.new

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

    # GET /pages/1/edit
    def edit
    @page = Page.find(params[:id])
    end

    # POST /pages
    # POST /pages.xml
    def create
    @page = Page.new(params[page])

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

    # PUT /pages/1
    # PUT /pages/1.xml
    def update
    @page = Page.find(params[:id])

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

    # DELETE /pages/1
    # DELETE /pages/1.xml
    def destroy
    @page = Page.find(params[:id])
    @page.destroy

    respond_to do |format|
    format.html { redirect_to(pages_url) }
    format.xml { head ok }
    end
    end
    end


    ---------------------------------------------------------
    Here's what the log looks like when I submit from the Pages New form


    Processing PagesController#index (for 127.0.0.1 at 2008-07-08 21:00:26) [post]
    Session ID: 0558cda0d915f27f4115d97058936cf9
    Parameters: {"commit"=>"Create", "authenticity_token"=>"ce8a170e56f86f6584f369dd2ca2d08e104e79d4", "action"=>"index", "controller"=>"pages", "page"=>{"title"=>"Test Title", "content"=>"Test Content\r\n", "enabled_flag"=>"1"}}
    Page Load (0.000693) SELECT * FROM `pages`
    Rendering template within layouts/application
    Rendering pages/index
    Completed in 0.00814 (122 reqs/sec) | Rendering: 0.00116 (14%) | DB: 0.00196 (24%) | 200 OK [http://0.0.0.0/pages]

  3. #3
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't think I have a confirmed answer for you, but when you submit a form it should post the data to PagesController#create, not index. It could be that the form that you're using is hitting the wrong URL upon submission.

    I also reserve the right to retract this post in the case that I overlooked an obvious error. That might be the case considering you're doing a pretty vanilla scaffolding, and the regular Rails scaffolding should be pretty straightforward out-of-the-box.

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    Houston, Texas, USA
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The form is definitely calling the wrong action upon submission.

    I have not changed any of the code generated by the scaffold. I did rename the layout so that it would use my application layout. Even using the original layout, it does not work.

    I have another model called 'announcement' that was generated with the scaffold also and it works without a problem.

    My first guess was that some how I'm using reserved words in my model and that maybe that's causing a problem. But none of the field names I have for the Page model are on any reserved lists.

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    Houston, Texas, USA
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I zipped up the application from the MacBook and put it here: http://www.colorcombos.com/apip_rails/

    The MySQL database name should be apip_development.

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would recommended trying another scaffold with a different name. You might be right about its name. I had a movie website, and I created a quotes resource and I had nothing but problems, very weird behaviour. Renamed it moviequotes and all the problems went away.

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2001
    Location
    Houston, Texas, USA
    Posts
    559
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Delameko View Post
    I would recommended trying another scaffold with a different name. You might be right about its name. I had a movie website, and I created a quotes resource and I had nothing but problems, very weird behaviour. Renamed it moviequotes and all the problems went away.
    Thanks for the reply.

    Here's something I found. In actionpack-2.1.0 there's a file called
    caching, that has a module called Pages.

    I changed the name of my resource to CustomPages and now it works.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •