Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default has_many does not update association #53

Closed
denispeplin opened this issue Jan 22, 2013 · 6 comments
Closed

Default has_many does not update association #53

denispeplin opened this issue Jan 22, 2013 · 6 comments

Comments

@denispeplin
Copy link

I created two models without explicitly specifying associations in Netzke.

class User < ActiveRecord::Base
  attr_accessible :email, :name
  has_many :pages
end

class Page < ActiveRecord::Base
  belongs_to :user
  attr_accessible :name, :url
end

class Pages < Netzke::Basepack::Grid
  def configure(c)
    super
    c.model = "Page"
  end
end

When I'm editing Page, it does update all the attributes except User. I selected User from drop-down list, but its parameter passed to netzke controller looks incorrect: \"user__name\":1 and in result user_id after updating is nil.

I've put code into repository: https://github.com/denispeplin/extjs_tut/tree/ne (uses netzke from gem in this tag, but I also tried with current netzke, same issue).

Post parameters:

Started POST "/netzke/direct/?authenticity_token=BaQAb8Gnadh6G3SkUZyY1nyA3S6fJACWEdwZN4FQZDI%3D" for 127.0.0.1 at 2013-01-22 10:08:18 +0400
Processing by NetzkeController#direct as HTML
  Parameters: {"act"=>"pages__edit_window__edit_form", "method"=>"netzkeSubmit", "data"=>[{"data"=>"{\"id\":\"2\",\"name\":\"testpage\",\"url\":\"www.example.com\",\"user__name\":1,\"created_at\":\"2013-01-21 12:19:56\",\"updated_at\":\"2013-01-22 05:01:39\"}"}], "type"=>"rpc", "tid"=>5, "authenticity_token"=>"BaQAb8Gnadh6G3SkUZyY1nyA3S6fJACWEdwZN4FQZDI=", "netzke"=>{"act"=>"pages__edit_window__edit_form", "method"=>"netzkeSubmit", "data"=>[{"data"=>"{\"id\":\"2\",\"name\":\"testpage\",\"url\":\"www.example.com\",\"user__name\":1,\"created_at\":\"2013-01-21 12:19:56\",\"updated_at\":\"2013-01-22 05:01:39\"}"}], "type"=>"rpc", "tid"=>5}}

Not sure it is netzke-core issue, maybe it is just component does not work properly.

@mxgrn
Copy link

mxgrn commented Jan 22, 2013

It's a common mistake. Just add :user_id to the attr_accessible list.

Sent from my iPhone

On 22 jan. 2013, at 14:20, Denis notifications@github.com wrote:

I created two models without explicitly specifying associations in Netzke.

class User < ActiveRecord::Base
attr_accessible :email, :name
has_many :pages
end

class Page < ActiveRecord::Base
belongs_to :user
attr_accessible :name, :url
end

class Pages < Netzke::Basepack::Grid
def configure(c)
super
c.model = "Page"
end
end
When I'm editing Page, it does update all the attributes except User. I selected User from drop-down list, but its parameter passed to netzke controller looks incorrect: "user__name":1 and in result user_id after updating is nil.

I've put code into repository: https://github.com/denispeplin/extjs_tut/tree/ne

Post parameters:

Started POST "/netzke/direct/?authenticity_token=BaQAb8Gnadh6G3SkUZyY1nyA3S6fJACWEdwZN4FQZDI%3D" for 127.0.0.1 at 2013-01-22 10:08:18 +0400
Processing by NetzkeController#direct as HTML
Parameters: {"act"=>"pages__edit_window__edit_form", "method"=>"netzkeSubmit", "data"=>[{"data"=>"{"id":"2","name":"testpage","url":"www.example.com","user__name":1,"created_at":"2013-01-21 12:19:56","updated_at":"2013-01-22 05:01:39"}"}], "type"=>"rpc", "tid"=>5, "authenticity_token"=>"BaQAb8Gnadh6G3SkUZyY1nyA3S6fJACWEdwZN4FQZDI=", "netzke"=>{"act"=>"pages__edit_window__edit_form", "method"=>"netzkeSubmit", "data"=>[{"data"=>"{"id":"2","name":"testpage","url":"www.example.com","user__name":1,"created_at":"2013-01-21 12:19:56","updated_at":"2013-01-22 05:01:39"}"}], "type"=>"rpc", "tid"=>5}}
Not sure it is netzke-core issue, maybe it is just component does not work properly.


Reply to this email directly or view it on GitHub.

@denispeplin
Copy link
Author

Added, restarted server, reloaded page. Still does not work. Netzke keeps passing user_id as user_name parameter.

@mxgrn
Copy link

mxgrn commented Jan 22, 2013

This is intended - a foreign key value is always passed as a value for assoc column. Can you post your final models code?

Sent from my iPhone

On 22 jan. 2013, at 15:22, Denis notifications@github.com wrote:

Added, restarted server, reloaded page. Still does not work. Netzke keeps passing user_id as user_name parameter.


Reply to this email directly or view it on GitHub.

@denispeplin
Copy link
Author

That was right request! Somehow I mistakenly put this :user_id to User model itself.

So now my Page model looks like:

class Page < ActiveRecord::Base
  belongs_to :user
  attr_accessible :name, :url, :user_id
end

And it works!

Thank you!

Just one thing that is probably wrong: when I' working with standard Rails, and if its need to mass-assign some protected attribute, it will complain loudly, raising an exception. But Netzke does not even displays a warning.

@mxgrn
Copy link

mxgrn commented Jan 23, 2013

Just one thing that is probably wrong: when I' working with standard
Rails, and if its need to mass-assign some protected attribute, it will
complain loudly, raising an exception. But Netzke does not even displays
a warning.

I agree, this should be fixed (in Basepack). Working on it right now.
Thanks for all your constructive feedback so far, looking forward for more!

@denispeplin
Copy link
Author

I'm almost sure it will be more feedback :)

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants