Note that there are some explanatory texts on larger screens.

plurals
  1. PORails code generated with ORM mangomapper throws NoMethodError (undefined method `each' for "4d2aeaea4403baa84a000005":String)
    primarykey
    data
    text
    <p>I am absolutely totally news to Rails and to MongoDB. I have been following tutorials from a good book and create my first Rails app with a light Twitter copy. Everything went fine and smooth.</p> <p>But as part of my learning process I wanted to build the same app using MongoDB rather than the default SGBD.</p> <p>I therefore configured mongo and installed the mongo_mapper gem. Everything has been configured properly following this tutorial: <a href="http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started" rel="nofollow noreferrer">http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started</a>. Then I struggled a little bit to allow Rails generate to work without throwing me the --orm not specified error. In order to get past this I had to add the rails3-generators gem and add it to the Gemfile.</p> <p>Once all this was done, everything worked fine. I was able to successfully launch the Rails server.</p> <p>I added a User controller thanks to the generate. The page works fine and even lists the users I have previously added:</p> <p><img src="https://i.stack.imgur.com/zXlFM.jpg" alt="alt text"></p> <p>However all the other actions, showing, editing, deleting, etc. are not working (creating works, but then it goes to show and the errors comes):</p> <p><img src="https://i.stack.imgur.com/n6GbK.jpg" alt="alt text"></p> <p>It's virtually the same error for all different actions.</p> <p>The one difference I can notice right off the bat is that with the non MongoDB db, the id's of the user was starting at 1, etc. but here with MongoDB it looks like a randomly generated id that is much more complex and that is not of type int: 4d2ae91d4403baa84a000002</p> <p>I am thinking that this may be creating the issues, since all action are using the id as a parameter... but I have no idea how to fix this. I have looked at the ruby generated code and it looks alright to me (extremely similar to the code generate for the default db).</p> <p>Any help would be greatly appreciated ! I don't know how to go forward with my project without solving a simple generate code with mongodb.</p> <p>Thanks,</p> <p>Alex</p> <p>ps: please that I did not write any of this code at all. everything has been generated, which is kinda why I expected to work from the get go...</p> <p>as asked here is the code for users_controllers:</p> <pre><code>class UsersController &lt; ApplicationController # GET /users # GET /users.xml def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml =&gt; @users } end end # GET /users/1 # GET /users/1.xml def show @user = User.first(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml =&gt; @user } end end # GET /users/new # GET /users/new.xml def new @user = User.new respond_to do |format| format.html # new.html.erb format.xml { render :xml =&gt; @user } end end # GET /users/1/edit def edit @user = User.first(params[:id]) end # POST /users # POST /users.xml def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice =&gt; 'User was successfully created.') } format.xml { render :xml =&gt; @user, :status =&gt; :created, :location =&gt; @user } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @user.errors, :status =&gt; :unprocessable_entity } end end end # PUT /users/1 # PUT /users/1.xml def update @user = User.first(params[:id]) respond_to do |format| if @user.update(params[:user]) format.html { redirect_to(@user, :notice =&gt; 'User was successfully updated.') } format.xml { head :ok } else format.html { render :action =&gt; "edit" } format.xml { render :xml =&gt; @user.errors, :status =&gt; :unprocessable_entity } end end end # DELETE /users/1 # DELETE /users/1.xml def destroy @user = User.first(params[:id]) @user.destroy respond_to do |format| format.html { redirect_to(users_url) } format.xml { head :ok } end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload