Ruby on Rails
Thursday, April 30, 2015
I would like to try ActionCable and will contribute documentation if needed.
Is this project available anywhere yet? How can I participate?
Steven
-- Is this project available anywhere yet? How can I participate?
Steven
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/453fa567-474f-42f2-8756-64e4c74a808c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
Very, very kind.... I do now feel very motivated and it seems that I have finally discovered a support system. May take me days to restructure my site www.echomarket.org to prove or demonstrate my difficulties. Otherwise I thank you sincerely.
Liz
On Thursday, April 30, 2015 at 11:50:10 AM UTC-4, Chris Lerum wrote:
-- Liz
On Thursday, April 30, 2015 at 11:50:10 AM UTC-4, Chris Lerum wrote:
It's to your credit that you got that working, but it's far from conventional - why not post your attempt to get associations working, with your expected result vs. actual, and you'll soon be greeted with a nice 'AHA!' moment. I bet.
On Thursday, April 30, 2015 at 10:18:28 AM UTC-4, Elizabeth McGurty wrote:
I don't know if this is an acceptable practice, but I do the following on update... and it works for me, especially as I have not been been to get table associations to work.
def update
unless params[:id].blank?
unless params[:parent_object].blank?
@p_o_hold = ParentObject.find(params[id])
unless @p_o_hold.blank?
myupdatehash = Hash.new
///// Then I select from params[:parent_object] that I need and apply some validation or database format requirements
myupdatehash = [:field => ...., ]
if @p_o_hold.update_attributes(myupdatehash[0])
@child_object = ChildObject.find(@p_o_hold.id)
unless @child_object.blank?
myupdatehash = [:child_field => @p_o_hold.child_field_value] ## hash object reuse
@child_object.update_attributes(myupdatehash[0])
.....
On Wednesday, April 29, 2015 at 4:42:05 AM UTC-4, Jagmeet Singh wrote:I am inserting a record in 1st table named as Students and I want to insert a record in another table with a value coming from a column Refid which is in Students table
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3ff901fa-8ac6-4966-a5cd-0d38f4225f53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
It's to your credit that you got that working, but it's far from conventional - why not post your attempt to get associations working, with your expected result vs. actual, and you'll soon be greeted with a nice 'AHA!' moment. I bet.
On Thursday, April 30, 2015 at 10:18:28 AM UTC-4, Elizabeth McGurty wrote:
-- On Thursday, April 30, 2015 at 10:18:28 AM UTC-4, Elizabeth McGurty wrote:
I don't know if this is an acceptable practice, but I do the following on update... and it works for me, especially as I have not been been to get table associations to work.
def update
unless params[:id].blank?
unless params[:parent_object].blank?
@p_o_hold = ParentObject.find(params[id])
unless @p_o_hold.blank?
myupdatehash = Hash.new
///// Then I select from params[:parent_object] that I need and apply some validation or database format requirements
myupdatehash = [:field => ...., ]
if @p_o_hold.update_attributes(myupdatehash[0])
@child_object = ChildObject.find(@p_o_hold.id)
unless @child_object.blank?
myupdatehash = [:child_field => @p_o_hold.child_field_value] ## hash object reuse
@child_object.update_attributes(myupdatehash[0])
.....
On Wednesday, April 29, 2015 at 4:42:05 AM UTC-4, Jagmeet Singh wrote:I am inserting a record in 1st table named as Students and I want to insert a record in another table with a value coming from a column Refid which is in Students table
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/717aaec5-c62c-4502-a70e-5109aeb65881%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
Small update. I have played with the GC and have run several tests. I manage to solve the problem by disabling the GC with GC.disable, but then my memory gets filled with garbages. I have also disabled hugepages on linux and no effects. Finally I've played with some of the parameters of the GC like the heap size, and reducing its activity to 0 (GC.count) but no changes. Every test have been performed on the same machine with the same parameters.
Ruby -v 2.2.1
-- Ruby -v 2.2.1
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f2c72b69-b16f-42a6-adcf-ee02f8e8aa9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
This is really driving me insane. I've something very similar to your sample Here. I've specified table names inside models. But still the error occurs. Would you mind taking a look at it ? Thank you a lot so far for your time.
On Thursday, April 30, 2015 at 3:59:45 PM UTC+3, Chris Lerum wrote:
-- On Thursday, April 30, 2015 at 3:59:45 PM UTC+3, Chris Lerum wrote:
https://github.com/chrislerum/factory setting table_name seems to be the sweet spot, working now
On Thursday, April 30, 2015 at 8:01:49 AM UTC-4, Chris Lerum wrote:you could try, in the model, self.table_name = "seven_gallery_photos" etc.On Thu, Apr 30, 2015 at 4:09 AM, Rafael Adel <rafael...@gmail.com> wrote:Are you sure about this ? If so, is there a way to make it working without changing table names ?
On Thursday, April 30, 2015 at 3:45:46 AM UTC+3, Chris Lerum wrote:In short, yes. See this lovely article; notice the conspicuous absence of any talk of changing table names:http://blog.makandra.com/2014/12/organizing-large-rails- projects-with-namespaces/
On Wednesday, April 29, 2015 at 1:59:04 PM UTC-4, Rafael Adel wrote:I can see the only difference is that in my case there's namespace in front of the table names and FK. But in yours there's none since it's a normal app.But is this the cause ?
On Wednesday, April 29, 2015 at 6:53:18 PM UTC+3, Chris Lerum wrote:https://github.com/chrislerum/factory I tried whipping up an app with your code, the controller test passes fine for me, see if it works for you and compare.
On Wednesday, April 29, 2015 at 10:32:47 AM UTC-4, Rafael Adel wrote:...I'm trying to create a `photo` factory that's in a many to one association with `gallery`. And I'm getting two errors, depending on how I specify the association between those two models.Here's the models:Photo
belongs_to :gallery, class_name: "SevenGallery::Gallery"
Gallery
has_many :photos, class_name: "SevenGallery::Photo", foreign_key: "seven_gallery_gallery_id", dependent: :destroyAnd the migrations
create_table :seven_gallery_galleries do |t|
t.string :title
t.timestamps null: false
end
create_table :seven_gallery_photos do |t|
t.string :caption
t.string :image
t.references :seven_gallery_gallery, index: true
t.timestamps null: false
end
add_foreign_key :seven_gallery_photos, :seven_gallery_galleries, on_delete: :cascadeNow Here's my factories:**Gallery**:
FactoryGirl.define do
factory :gallery, class: 'SevenGallery::Gallery' do
title "an event gallery"
factory :gallery_with_photos do
after(:build) do |gallery|
gallery.photos << FactoryGirl.create(:photo_one, seven_gallery_gallery_id: gallery)
gallery.photos << FactoryGirl.create(:photo_two, seven_gallery_gallery_id: gallery)
gallery.photos << FactoryGirl.create(:photo_three , seven_gallery_gallery_id: gallery)
end
end
end
endAnd **Photo**:
FactoryGirl.define do
factory :photo, class: "SevenGallery::Photo" do
factory :photo_one do
end
factory :photo_two do
end
factory :photo_three do
end
factory :photo_with_gallery do
gallery
end
end
endAnd here's the controller spec that generates the error:
it "changes is_main to true in self and false in rest" do
photo_one = FactoryGirl.create(:photo_with_gallery )
expect(photo_one.gallery).to be_a SevenGallery::Gallery
endWhenever I run the test I get this error:
Failure/Error: photo_one = FactoryGirl.create(:photo_with_gallery )
ActiveModel::MissingAttributeError :
can't write unknown attribute `gallery_id`
# ./spec/controllers/seven_gallery/photos_controller_ spec.rb: When I change the association part to be:
factory :photo_with_gallery do
association :gallery, factory: gallery
endI get this error:
Failure/Error: photo_one = FactoryGirl.create(:photo_with_gallery )
NoMethodError:
undefined method `name' for :photo_with_gallery:Symbol
# ./spec/controllers/seven_gallery/photos_controller_ spec.rb:8 **Backtrace**:
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute.rb: 138:in `with_value_from_database'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_set. rb:39:in `write_from_user'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods/write.rb:74:in `write_attribute_with_type_ cast'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods/write.rb:56:in `write_attribute'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods/dirty.rb:96:in `write_attribute'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods.rb:373:in `[]='
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ belongs_to_association.rb:83: in `replace_keys'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ belongs_to_association.rb:14: in `replace'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ singular_association.rb:17:in `writer'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ builder/association.rb:123:in `gallery='
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:16:in `public_send'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:16:in `block (2 levels) in object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:15:in `each'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:15:in `block in object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:14:in `tap'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:14:in `object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/evaluation.rb:12: in `object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/strategy/create. rb:9:in `result'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/factory.rb:42:in `run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/factory_runner. rb:23:in `block in run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activesupport-4.2.1/lib/ active_support/notifications. rb:166:in `instrument'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/factory_runner. rb:22:in `run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/strategy_syntax_ method_registrar.rb:20:in `block in define_singular_strategy_ method'
# ./spec/controllers/seven_gallery/photos_controller_ spec.rb:8:in `block (3 levels) in <module:SevenGallery>'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:177:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:177:in `block in run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:385:in `block in with_around_and_singleton_ context_hooks'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:343:in `block in with_around_example_hooks'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:474:in `block in run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:614:in `block in run_around_example_hooks_for'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-rails-3.2.1/lib/ rspec/rails/example/ controller_example_group.rb: 179:in `block (2 levels) in <module: ControllerExampleGroup>'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:387:in `execute_with'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-rails-3.2.1/lib/ rspec/rails/adapters.rb:113:in `block (2 levels) in <module: MinitestLifecycleAdapter>'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:387:in `execute_with'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/To view this discussion on the web visit https://groups.google.com/d/--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/ .roj0zJgpXVs/unsubscribe
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com .
To post to this group, send email to rubyonra...@googlegroups.com .msgid/rubyonrails-talk/ .d53dfd82-135c-4990-b21b- 3d030accbbbc%40googlegroups. com
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5dbcfc10-d039-481e-9729-a74fd45ea6b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
I don't know if this is an acceptable practice, but I do the following on update... and it works for me, especially as I have not been been to get table associations to work.
def update
unless params[:id].blank?
unless params[:parent_object].blank?
@p_o_hold = ParentObject.find(params[id])
unless @p_o_hold.blank?
myupdatehash = Hash.new
///// Then I select from params[:parent_object] that I need and apply some validation or database format requirements
myupdatehash = [:field => ...., ]
if @p_o_hold.update_attributes(myupdatehash[0])
@child_object = ChildObject.find(@p_o_hold.id)
unless @child_object.blank?
myupdatehash = [:child_field => @p_o_hold.child_field_value] ## hash object reuse
@child_object.update_attributes(myupdatehash[0])
.....
On Wednesday, April 29, 2015 at 4:42:05 AM UTC-4, Jagmeet Singh wrote:
I am inserting a record in 1st table named as Students and I want to insert a record in another table with a value coming from a column Refid which is in Students table
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2dfa36b3-b11b-4f1a-87b7-e8916aabfadb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
I don't know if this is an acceptable practice, but I do the following on update... and it works for me
def update
unless params[:id].blank?
unless params[:parent_object].blank?
@p_o_hold = @parent_object.find(params[id])
unless @p_o_hold.blank?
myupdatehash = Hash.new
///// Then I select from params[:parent_object] that I need and apply some validation or database format requirements
myupdatehash = [:field => ...., ]
if @p_o_hold.update_attributes(myupdatehash[0])
@child_object = ChildObject.find(@p_o_hold.id)
unless @child_object.blank?
myupdatehash = [:child_field => @p_o_hold.child_field_value] ## hash object reuse
@child_object.update_attributes(myupdatehash[0])
.....
On Wednesday, April 29, 2015 at 4:42:05 AM UTC-4, Jagmeet Singh wrote:
-- def update
unless params[:id].blank?
unless params[:parent_object].blank?
@p_o_hold = @parent_object.find(params[id])
unless @p_o_hold.blank?
myupdatehash = Hash.new
///// Then I select from params[:parent_object] that I need and apply some validation or database format requirements
myupdatehash = [:field => ...., ]
if @p_o_hold.update_attributes(myupdatehash[0])
@child_object = ChildObject.find(@p_o_hold.id)
unless @child_object.blank?
myupdatehash = [:child_field => @p_o_hold.child_field_value] ## hash object reuse
@child_object.update_attributes(myupdatehash[0])
.....
On Wednesday, April 29, 2015 at 4:42:05 AM UTC-4, Jagmeet Singh wrote:
I am inserting a record in 1st table named as Students and I want to insert a record in another table with a value coming from a column Refid which is in Students table
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/30591aec-161b-4a99-8929-9b921cd613a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
I think the model for your form should be @member, the last object in your controller def new
On Wednesday, April 29, 2015 at 5:15:28 PM UTC-4, nic...@gmail.com wrote:
-- On Wednesday, April 29, 2015 at 5:15:28 PM UTC-4, nic...@gmail.com wrote:
I have two models each with their own resources: Organizations and Members. An organization has multiple members and a member is only a member to one organization.
How can I create a simple nested form that signs up a new organization as well as one member for that organization?
My current attempt is below. On submitting the form, this however generates the error message
unknown attribute 'org_name' for Member, which I don't get especially since org_name is a column within the Organization model and not the Member model.
Organization model
has_many :members, dependent: :destroy
accepts_nested_attributes_for :members, :reject_if => :all_blank, :allow_destroy => true
Member model
belongs_to :organization
Organizations controller
def new
@organization = Organization.new
@member = @organization.members.build
end
def create
@organization = Organization.new(organizationnew_params )
@member = @organization.members.build(organizationnew_params )
if @organization.save && @member.save
@member.send_activation_email #Will Rails be able to get to this method? The send_activation_email method exists in multiple models and Rails should here use the version from the Member model.
flash[:success] = "Please check your email to activate your account."
redirect_to root_url
else
render 'new'
end
end
def organizationnew_params
params.require(:organization).permit (:org_name,
:phone,
member_attributes: [:email,
:username,
:admin,
:password,
:password_confirmation
])
endOrganizations new view
<%= form_for(@organization) do |f| %>
<%= f.text_field :org_name, %>
<%= f.text_field :phone %>
<%= f.fields_for :member do |p| %>
<%= p.text_field :username %>
<%= p.email_field :email %>
<%= p.password_field :password %>
<%= p.password_field :password_confirmation %>
<%= hidden_field_tag :admin, true %>
<% end %>
<%= f.submit "Sign up", class: "formbutton btn btn-default" %>
<% end %>What am I doing wrong? How can I create a simple nested form?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7aea7e3f-dda7-42da-af52-d0f97d17f82e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ruby on Rails
https://github.com/chrislerum/factory setting table_name seems to be the sweet spot, working now
On Thursday, April 30, 2015 at 8:01:49 AM UTC-4, Chris Lerum wrote:
-- On Thursday, April 30, 2015 at 8:01:49 AM UTC-4, Chris Lerum wrote:
you could try, in the model, self.table_name = "seven_gallery_photos" etc.On Thu, Apr 30, 2015 at 4:09 AM, Rafael Adel <rafael.adel20@gmail.com> wrote:Are you sure about this ? If so, is there a way to make it working without changing table names ?
On Thursday, April 30, 2015 at 3:45:46 AM UTC+3, Chris Lerum wrote:In short, yes. See this lovely article; notice the conspicuous absence of any talk of changing table names:http://blog.makandra.com/2014/12/organizing-large-rails- projects-with-namespaces/
On Wednesday, April 29, 2015 at 1:59:04 PM UTC-4, Rafael Adel wrote:I can see the only difference is that in my case there's namespace in front of the table names and FK. But in yours there's none since it's a normal app.But is this the cause ?
On Wednesday, April 29, 2015 at 6:53:18 PM UTC+3, Chris Lerum wrote:https://github.com/chrislerum/factory I tried whipping up an app with your code, the controller test passes fine for me, see if it works for you and compare.
On Wednesday, April 29, 2015 at 10:32:47 AM UTC-4, Rafael Adel wrote:...I'm trying to create a `photo` factory that's in a many to one association with `gallery`. And I'm getting two errors, depending on how I specify the association between those two models.Here's the models:Photo
belongs_to :gallery, class_name: "SevenGallery::Gallery"
Gallery
has_many :photos, class_name: "SevenGallery::Photo", foreign_key: "seven_gallery_gallery_id", dependent: :destroyAnd the migrations
create_table :seven_gallery_galleries do |t|
t.string :title
t.timestamps null: false
end
create_table :seven_gallery_photos do |t|
t.string :caption
t.string :image
t.references :seven_gallery_gallery, index: true
t.timestamps null: false
end
add_foreign_key :seven_gallery_photos, :seven_gallery_galleries, on_delete: :cascadeNow Here's my factories:**Gallery**:
FactoryGirl.define do
factory :gallery, class: 'SevenGallery::Gallery' do
title "an event gallery"
factory :gallery_with_photos do
after(:build) do |gallery|
gallery.photos << FactoryGirl.create(:photo_one, seven_gallery_gallery_id: gallery)
gallery.photos << FactoryGirl.create(:photo_two, seven_gallery_gallery_id: gallery)
gallery.photos << FactoryGirl.create(:photo_three , seven_gallery_gallery_id: gallery)
end
end
end
endAnd **Photo**:
FactoryGirl.define do
factory :photo, class: "SevenGallery::Photo" do
factory :photo_one do
end
factory :photo_two do
end
factory :photo_three do
end
factory :photo_with_gallery do
gallery
end
end
endAnd here's the controller spec that generates the error:
it "changes is_main to true in self and false in rest" do
photo_one = FactoryGirl.create(:photo_with_gallery )
expect(photo_one.gallery).to be_a SevenGallery::Gallery
endWhenever I run the test I get this error:
Failure/Error: photo_one = FactoryGirl.create(:photo_with_gallery )
ActiveModel::MissingAttributeError :
can't write unknown attribute `gallery_id`
# ./spec/controllers/seven_gallery/photos_controller_ spec.rb: When I change the association part to be:
factory :photo_with_gallery do
association :gallery, factory: gallery
endI get this error:
Failure/Error: photo_one = FactoryGirl.create(:photo_with_gallery )
NoMethodError:
undefined method `name' for :photo_with_gallery:Symbol
# ./spec/controllers/seven_gallery/photos_controller_ spec.rb:8 **Backtrace**:
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute.rb: 138:in `with_value_from_database'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_set. rb:39:in `write_from_user'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods/write.rb:74:in `write_attribute_with_type_ cast'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods/write.rb:56:in `write_attribute'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods/dirty.rb:96:in `write_attribute'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/attribute_ methods.rb:373:in `[]='
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ belongs_to_association.rb:83: in `replace_keys'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ belongs_to_association.rb:14: in `replace'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ singular_association.rb:17:in `writer'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activerecord-4.2.1/lib/ active_record/associations/ builder/association.rb:123:in `gallery='
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:16:in `public_send'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:16:in `block (2 levels) in object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:15:in `each'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:15:in `block in object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:14:in `tap'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/attribute_ assigner.rb:14:in `object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/evaluation.rb:12: in `object'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/strategy/create. rb:9:in `result'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/factory.rb:42:in `run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/factory_runner. rb:23:in `block in run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/activesupport-4.2.1/lib/ active_support/notifications. rb:166:in `instrument'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/factory_runner. rb:22:in `run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/factory_girl-4.5.0/lib/ factory_girl/strategy_syntax_ method_registrar.rb:20:in `block in define_singular_strategy_ method'
# ./spec/controllers/seven_gallery/photos_controller_ spec.rb:8:in `block (3 levels) in <module:SevenGallery>'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:177:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:177:in `block in run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:385:in `block in with_around_and_singleton_ context_hooks'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:343:in `block in with_around_example_hooks'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:474:in `block in run'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:614:in `block in run_around_example_hooks_for'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-rails-3.2.1/lib/ rspec/rails/example/ controller_example_group.rb: 179:in `block (2 levels) in <module: ControllerExampleGroup>'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:387:in `execute_with'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-rails-3.2.1/lib/ rspec/rails/adapters.rb:113:in `block (2 levels) in <module: MinitestLifecycleAdapter>'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:333:in `instance_exec'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:387:in `execute_with'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
# /home/rafael/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/ gems/rspec-core-3.2.3/lib/ rspec/core/example.rb:247:in `call'
# /home/rafael/To view this discussion on the web visit https://groups.google.com/d/--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/ .roj0zJgpXVs/unsubscribe
To unsubscribe from this group and all its topics, send an email to rubyonrails-talk+unsubscribe@googlegroups.com .
To post to this group, send email to rubyonrails-talk@googlegroups.com .msgid/rubyonrails-talk/ .d53dfd82-135c-4990-b21b- 3d030accbbbc%40googlegroups. com
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5cc48b3a-0a80-4926-9165-480cffc5ea7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Posts (Atom)