[merb][bug?] Update method not working (not saving stuff)

6 views
Skip to first unread message

Andre

unread,
Nov 22, 2008, 2:32:10 PM11/22/08
to merb
Ok, so I upgraded to Merb 1.0.1 and DataMapper 0.9.7. The thing is
that now the update function of my controller is completely broken.
Let me explain better.

I'm doing some very basic stuff. I create my app, set up the database
and then generate my resource with:

merb-gen resource article title:string,author:string

I then ran the rake db:automigrate command, to sync my database. After
that I've created my views following exactly the examples listed here:
http://wiki.merbivore.com/howto/crud_view_example_with_merb_using_erb

Then I proceed to actually create my first content. All's fine. The
record is created and correctly displayed. Still, when I go and edit
it the data isn't saved. Let me clarify that I haven't touched a
single thing in my controller.
"It could be a DataMapper problem", I thought. So i ran "merb -i" and
tried to do stuff from there:

Article.get(1).update_attributes(:title => "My new title")

And the record gets updated just fine. By the way, the problems
persists even if I use ActiveRecord.
So I've tried to se if it was a merb problem by modifying the update
method of my controller like this, you know just to do some
experiments to get at least a hint of what's going on:

def update(id, article)
@article = Article.get(id)
raise NotFound unless @article
if @article.update_attributes(:title => "bla bla bla")
redirect resource(@article)
else
display @article, :edit
end
end

The record is updated again, and "bla bla bla" is my new title. Then I
restored the fourth line of the code posted above to what's
automatically generated by merb-gen:

...
if @article.update_attributes(article)
...

Again, nothing saved. It seems to me like the article variable isn't
read by the @article.update_attributes function, at all :/

What could be wrong? I've updated all the gems, and I've done some
very basic stuff, with no models relationships established, nor
validations etc... Any ideas about this very weird behaviour?

Thankyou so much in advance.

Andre

unread,
Nov 22, 2008, 2:54:30 PM11/22/08
to merb
nevermind... I really don't know what I've done, but for some reason
it works now :/ I haven't changed a single line of code... I've just
set up my application again from ground up...

Peter Dirickson

unread,
Nov 23, 2008, 12:25:12 AM11/23/08
to me...@googlegroups.com
Andre,

Did you had dependency "merb-action-args" setup up?

That's what using when you do:

def update(id, article)

instead of

def update(params[:id], params[:article])

Peter.

Andre

unread,
Nov 23, 2008, 6:26:34 PM11/23/08
to merb
Yeah, I've had included that dependency in my dependencies.rb file...

Still, I get this strange behaviour again, but only for the title
field of my resource... Like, everything is saved but the title. It's
just weird, everything else is working fine...



On 23 Nov, 06:25, "Peter Dirickson" <pete...@gmail.com> wrote:
> Andre,
>
> Did you had dependency "merb-action-args" setup up?
>
> That's what using when you do:
>
> def update(id, article)
>
> instead of
>
> def update(params[:id], params[:article])
>
> Peter.
>

Andre

unread,
Nov 23, 2008, 6:54:29 PM11/23/08
to merb
I'm further investigating the problem. I've tried to update the title
field, no success. I've created another string field called
"headline", and I've tried to update it (always with the
update_attributes function). Again, no success. The only way for me to
update the title field or the headline field is:

@article.title = article['title']
@article.save

But then I've created another field, called "articletitle", and, with
great surprise from me, this worked fine.

If I check the logs, with 'title' and 'headline' the update sql
function is performed only on my other fields (namely 'body' and
'excerpt'), while for 'articletitle', all the fields are correctly
updated.

So, could it be a naming problem? Like some keywords are reserved, and
some others aren't? Other than that I really can't explain this weird
behaviour.


Are there any merb devs that can make it clear about my problem?

Thanks!

Ryan Bigg

unread,
Nov 23, 2008, 7:19:54 PM11/23/08
to me...@googlegroups.com
sounds like attr_accessible
-----
Ryan Bigg
Freelancer
http://frozenplague.net

Michael Klishin

unread,
Nov 24, 2008, 4:20:43 AM11/24/08
to me...@googlegroups.com
2008/11/24 Andre <andrea...@gmail.com>:

> Are there any merb devs that can make it clear about my problem?

Paste your model code and your action code. Making guesses is hard.
--
MK

Thomas Lee

unread,
Nov 24, 2008, 5:41:59 AM11/24/08
to me...@googlegroups.com
I'm experiencing something very similar to what's been described in this
issue and I'm definitely not using attr_accessible.

Or are you saying that attr_accessible is *required*?

Cheers,
T

Thomas Lee

unread,
Nov 24, 2008, 5:47:50 AM11/24/08
to me...@googlegroups.com
Here's a bit more background information:

I'm personally using DataMapper. My action code looks like this:

@foo = Foo.get(params[:id])
target = :failure
if @foo.verification_code == params[:code]
if @foo.update_attributes(:status => Foo::ACTIVE)
target = :success
end
end
render target

This renders the "success" view. In the model:

property :status, String, :nullable => false

validates_format :status, :with => Proc.new { |value|
[INACTIVE, PENDING, ACTIVE].include?(value)
}

Nothing else implies the inclusion or exclusion of the status property
wrt updates.

Any ideas?

Cheers,
T

Thomas Lee

unread,
Nov 24, 2008, 5:52:31 AM11/24/08
to me...@googlegroups.com
Oh and I should probably mention that logging the SQL indicates that no
attempts are made by DM to actually update any records.

Thomas Lee

unread,
Nov 24, 2008, 6:09:59 AM11/24/08
to me...@googlegroups.com
For those interested, this is being discussed here:

http://wm.lighthouseapp.com/projects/4819/tickets/664-no-record-update-after-upgrade-to-097#ticket-664-5

A temporary work-around suggested by sickill on #merb was to add the
:lazy => false option to a Text property in my model.

Supposedly this "only" affects models with Text properties and/or
associations. Ouch ...

tongueroo

unread,
Nov 27, 2008, 1:00:44 AM11/27/08
to merb
This is crazy, I am having the exact same issue. In the console it
works fine but in merb it doesnt save. You ever figure out the issue?

Thanks,
Tung

tongueroo

unread,
Nov 27, 2008, 1:09:27 AM11/27/08
to merb
Andre,

I am getting the same type of error. I upgraded from merb 1.0 to
1.0.3 and datamapper 0.9.7 to 0.9.8. Have you made any progress?

Thanks,
Tung

On Nov 22, 11:32 am, Andre <andreagand...@gmail.com> wrote:

pnomolos

unread,
Nov 27, 2008, 3:42:11 AM11/27/08
to merb
Just a note ... here's the update link to lighthouse (since the moved
the project around) http://datamapper.lighthouseapp.com/projects/20609/tickets/664-no-record-update-after-upgrade-to-097
Reply all
Reply to author
Forward
0 new messages