Rails 4 activeadmin - undefined local variable or method `view_factory' for :Arbre::Context - activeadmin

i am using activeadmin gem for my admin interface,now i created a new controller and added layout 'acitveadmin'
am getting the below error
NameError in MeetingRooms#index
Showing /home/amp/.rvm/gems/ruby-2.1.1#rails4.1/bundler/gems/active_admin-41d5176f3682/app/views/layouts/active_admin.html.arb
where line #2 raised:
undefined local variable or method `view_factory' for :Arbre::Context
my controller is
app/controllers/meeting_rooms_controller.rb
class MeetingRoomsController < ApplicationController
layout 'active_admin'
def index
#meeting_rooms = MeetingRoom.all
#render :layout => "active_admin"
end
end
can any one please help me.

I think you should use the controller block to define actions.
https://github.com/activeadmin/activeadmin/blob/master/docs/8-custom-actions.md#modifying-the-controller
ActiveAdmin.register MeetingRoom do
controller do
# This code is evaluated within the controller class
def define_a_method
# Instance method
end
end
end
In the controller block you can use the feature of the InheritedResources.
https://github.com/josevalim/inherited_resources#overwriting-actions

Related

how to fix "Rendered ActiveModel::Serializer::Null with Hash"

I am trying to write API for user model, where i have to return only two columns with some modification(appending string)
Every thing work's fine, I even get the correct result, but when I see status code its showing '500', when i check the logs its showed the following error
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash
following is the code
1. users_controller.rb
class Api::V1::UsersController < Api::V1::ApiController
# GET
def pl_details
render json: {pl: current_user.pl_url, enabled: current_user.personal_calendar_enabled}, status: :success
end
...
end
user.rb
...
def pl_url
return "#{Rails.application.secrets.app_host}/#{self.calendar_url_token}"
end
...
user_serializer.rb
class UserSerializer < ActiveModel::Serializer
attributes :id, :firstname, :lastname, :email
end
Never mind,
I just did it other way around,I used a separate Serializer to avoid the error, following is the approach
class Api::V1::UsersController < Api::V1::ApiController
# GET
def pl_details
render json: current_user,serializer: PLSerializer, status: :success
end
...
end
and inside PLSerializer
class PLSerializer < ActiveModel::Serializer
attributes :pl, :personal_calendar_enabled
def personal_link
current_user.pl_url
end
end

not handling the file upload window well

I have a page object called import_transaction_file.rb, which one of the method click_choose_file will invoke a standard file upload windows show below:
the code for the page object is:
class ImportTransactionFile
include PageObject
....
button(:choose_file, :id => 'createBulkPayment:file')
....
def click_choose_file
choose_file
end
end
In my test program below:
....
def test_go_to_direct_credit_payment_page
...
#import_transaction.click_choose_file
# #browser.window(:title => 'File Upload').use do
# #browser.button(:name => 'Cancel').click
# end
# doesn't work
end
the method click_choose_file in the test program will invoke the standard file upload window as attached below:
How do I:
put the path to file name
click open button
click close button
Will you recommend me to do it in the page-object or the test program?
Thanks for your reply.
I have a very similar thing to what you're asking and mine works using:
browser.file_field(:text, "File Upload").set("C:\path\to\file\to\upload")
Hope that helps!

page-object gem seems not working

I am trying to use page-object gem in my watir-webdriver scripts and I think I might be missing something.
Here is my code for log_in.rb:
require "./all_deals"
class LogIn
include PageObject
text_field(:email, :id => 'UserName')
text_field(:password, :id => 'Password')
checkbox(:remember_me, :id => 'RememberMe')
button(:log_me_in, :value => 'Login')
def initialize(browser)
#browser = browser
end
def log_in (email, password)
self.email = email
self.password = password
remember_me
log_me_in
AllDeals.new(#browser)
end
end
My home_page.rb
require "./log_in"
class HomePage
def initialize(browser)
#browser = browser
end
def visit
#browser.goto "http://treatme.co.nz/"
end
def go_to_log_in
#browser.goto "https://treatme.co.nz/Account/LogOn"
LogIn.new(#browser)
end
end
Here is my log_in_test.rb
require "rubygems"
require "test/unit"
require "watir-webdriver"
require "page-object"
require "./home_page"
class LogInTest < Test::Unit::TestCase
def setup
#browser ||= Watir::Browser.new :firefox
end
def teardown
#browser.close
end
def test_fail
#home_page = HomePage.new(#browser)
#home_page.visit
#log_in_page = #home_page.go_to_log_in
#all_deals = #log_in_page.log_in("test#gmail.com","test")
assert (#all_deals.get_title == "GrabOne Daily Deals - Buy Together, Save Together")
end
end
The result of the test run is:
Finished tests in 22.469286s, 0.0445 tests/s, 0.0000 assertions/s.
1) Error:
test_fail(LogInTest):
NoMethodError: undefined method `text_field_value_set' for nil:NilClass
C:/Ruby193/lib/ruby/gems/1.9.1/gems/page-object-0.9.2/lib/page-object/accessors.rb:142:in `block in text_field'
I am using Ruby 1.9 with page-object gem 0.9.2.
Can you please help me?
Also in each of those rb file, I need to require the class files it references, is there a way I don't have to declare it every time?
Thanks so much.
Addressing the Exception
That exception is occurring do to the LogIn page re-defining the initialize method.
class LogIn
include PageObject
def initialize(browser)
#browser = browser
end
end
When you include PageObject, it already adds a specific initialization method. Your class is overriding that initialization and presumably causing something to not get setup correctly.
Removing the initialize method will get you past that exception.
However, you will then hit a remember_me is not a variable/method exception. Assuming you want to check the checkbox, it should be check_remember_me.
Requiring Class Files
I usually have my test file require a file that requires all my page_objects. It is a similar concept to how your would require any other gem or library.
For example, I would create a treatme.rb file with:
require 'log_in'
require 'home_page'
Assuming you require the files in the required order (ie files that are needed by others are required first), none of your page object files (ie log_in.rb and home_page.rb) should need to do any requiring.
Your test files would then just require your treatme.rb file. Example:
require './treatme'

Rails 4: Correct way to create objects from other model from the controller

Using strong_params from Rails 4, what is the preferred best way to do this?
I used the below solution but are uncertain if this is the best way to do it. ( it works though )
Example:
game_controller.rb ( shortcut version!)
# inside game controller we want to build an Participant object
# using .require fails, using .permits goes true
def GameController < ApplicationController
def join_game_as_participant
#participant = Participant.new(participant_params)
end
end
def participant_params
params.permit(:participant,
:participant_id,
:user_id,
:confirmed).merge(:user_id => current_user.id,
:game_id => params[:game_id])
end
Your participant_params method should be private and you should use the require method :
private
def participant_params
params.require(:participant).permit(
:participant_id, :user_id, :confirmed
).merge(
:user_id => current_user.id, :game_id => params[:game_id]
)
end
Hope this help

Why is there an error in the following code?

I would be grateful for help in sorting the error in the following code:
require 'rubygems'
require 'watir'
require 'watir-webdriver'
require 'test/unit'
class TestGoogle < Test::Unit::TestCase
def setup
#browser = Watir::Browser.new :firefox
end
def testSignInLink
#browser.goto "http://google.com/"
po = PageObjects.new(#browser)
po.clickLinkSignIn
end
end
class PageObjects
def initialize( browser )
#browser = browser
end
def clickLinkSignIn()
#browser.link(:id, "gb_70").click
end
end
tg = TestGoogle.new
tg.setup
tg.testSignInLink
The error is:
Uncaught exception: wrong number of arguments (0 for 1)
C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:971:in `initialize'
C:/RubymineProjects/ditto/Google_01_TU_02.rb:28:in `new'
C:/RubymineProjects/ditto/Google_01_TU_02.rb:28:in `<top (required)>'
Line 28 is:
tg = TestGoogle.new
Strangely enough, the script then runs to completion with the google login page being presented.
Note that there are no asserts yet - I'm doing this one small step at a time.
Added after edit:
The initializer in C:/Ruby193/lib/ruby/1.9.1/minitest/unit.rb:971
def initialize name # :nodoc:
#__name__ = name
#__io__ = nil
#passed = nil
end
I think this whole question was unfair to all the good commenters.
Reason: As an experiment, I commented out the last 3 lines of the code:
tg = TestGoogle.new
tg.setup
tg.testSignInLink
The test ran perfectly.
I was previously assuming that I needed some way to "kick start" the methods in the TestGoogle class. Similar to a "Main" program that calls all the methods in turn.
Maybe that's what #justinko was referring to? So, the TestGoogle class is a test runner?
I think I need to apologize to the commenters.

Resources