Actsaswizard Rails Plugin - ruby-on-rails

I'm having a problem implementing the example in the actaswizard readme, and I was wondering if my error would be obvious to anyone here.
My controllers, models, and migrations are exactly as shown here: https://github.com/adkron/actsaswizard
My routes are as follows:
match 'test' => 'employees#new'
resources :employees
However when I navigate to localhost/test I recieve the following error:
NoMethodError (undefined method state' for #<Employee:0x00000001c22ad0>):
app/controllers/employees_controller.rb:10:inedit'
Does anyone recognize this error, or have any advice on how to get around it? Thanks in advance for any help! In addition, if you know of any good guides or additional examples using this plugin I'd be grateful for them as well.

I think that the actsaswizard uses the AASM (acts as state machine) to navigate you through the steps. That is why you need to specify a field "state" for the model that actsaswizard! This means that you must run a migration that makes a column named state of string type. Let me know if that worked!

Related

Conflict between Rails Admin and Impressionist gems

I'm using the latest version of the Impressionist and Rails Admin gems, and wondering if anyone could shed some light on an annoying conflict I'm experiencing. The problem is roughly documented here - https://github.com/sferik/rails_admin/issues/1315, yet the vaguely described solution is not working for me. When I have the line is_impressionable in my Listing model, I get an error when starting my Rails server with rails s:
...rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `is_impressionable' for Listing(no database connection):Class (NameError)
If I first start the server, and then add the 'is_impressionable' line, everything works fine, so the problem only occurs during initialization. I don't fully understand the initialization process, so am not sure how to go about getting this to work.
I have tried moving all my rails_admin model configuration options to their respective models, rather than in the initializer, which had no effect. I also have the following line in my initializer:
config.included_models = [Listing,ListingImage,AllOtherModelsHere...]
I have tried adding single quotes around these model names, which results in the following errors, as described in the github issue here
[RailsAdmin] Could not load model Listing, assuming model is non existing. (undefined local variable or method `is_impressionable' for Listing(no database connection):Class)
Any ideas what else I can try to make these gems work together? I don't want to have to remove the is_impressionable line every time I want to restart the server or generate a migration...
Not sure if the same issue that I had but yet I will post what worked for me just in case someone struggles with this too:
Im on a ruby 2.1.5 project with rails 4.2.0 and among other gems I'm using rails admin.
I run into several weird problems trying to set this up. For instance if I added the is_impressionable call within one of my models for some reason the execution of that file stopped there and I started getting weird errors like any method declared below the is_impressionable failed with undefined error.
So what I end up doing was:
class MyModel < ActiveRecord::Base
include Impressionist::IsImpressionable
is_impressionable
end
So this solved my issue and now i can access #my_model_instance.impression_count as expected.
I changed every occurrence of Klass to 'Klass'.constantize in initializer.

One of my Mongoid models has forgotten that is a database object

So I have this model object Shop::Order, which has worked fine until now.
But today I get these weird errors in my forms Undefined method 'model_name' for Shop::Order:Class.
So I look around and test in my console, that all instances of Shop::Order don't have any persistence methods. But still my tests don't fail. So I load up the test console and there Shop::Order works perfectly.
This doesn't really make any sense to me and I'm quite frankly out of Ideas on how to solve this.
Here's a link to the model: Shop::Order
The error appears in this view: new.html.haml
All other models are working totally fine.
Any help would be appreciated.
The problem lays in config/initializers/contants.rb where you're predefining your Shop::Order class.
I assume what happens is, the autoloader does not search further once it already has the class defined.
You should remove it, as this is not the initializer use case to define model's constants.

NoMethodError undefined method '-#' NoMethodError in Controller Ruby on Rails

Context:
I pulled the most recent code from the repository and tried to make sure that the changes I was about to push up were going to work with that version of the code. This is a Ruby on Rails application. Also worth noting is the fact that when running the main application that I pulled from on the web, this error does not show up. But if I run my branch or the main branch cloned onto my environment, the error always shows up for every url I try. So it is on my end.
Problem:
As soon as I go to localhost:3000, I get the following error:
NoMethodError in HomeController#index
undefined method `-#' for #<ActionDispatch::Response:0x64fd460>
What I've Tried:
I have asked my question on the #rubyonrails IRC channel and nobody was able to determine what was going on through the Full Trace (I haven't posted it here because I wasn't sure what was the best way to do that on here; it didn't look very good in the code block or block quote). I have looked at my HomeController's index method, which is defined as such:
def index
#groups = #current_user.groups
#things = Thing.where(:group_id => #groups.map{|e|e.id})
end
I have also Googled around and haven't found what I need to fix the problem.
What I've Learned So Far:
-# is an operator. Some people may receive a similar error in assuming that Ruby has the shortcut to
variable = variable + 1
that a lot of other languages have:
variable++
Here is an example of that case: Undefined method `+#' for false:FalseClass (NoMethodError) ruby
Question:
Does anyone have any further suggestions on how to find the issue here? Also, if I could easily put the Full Trace on here, formatted in an aesthetically pleasing manner, would someone tell me how? I'm at a loss with this one :(
Update (2/8/2013):
It seems that the issue does not necessarily reside in the HomeController nor home/index.html.erb View. I have attempted to access ANY url with a valid action and the same error occurs with "NoMethodError in..." changing to the corresponding [...]Controller#index.
Update (2/9/2013):
Since this error happens no matter what url I try to navigate to, I decided to look in the routes.rb file in the config folder. I ran my server through rubymine instead of the command line this time, which made it a little easier to read for me. I started looking through all the spit out and I noticed an interested line that consisted of:
["private-key looking thing"] [127.0.0.1] Started GET "/" for 127.0.0.1 at 2013-02-09 18:20:52 -0700
It seems like there is a syntactical error in routes.rb (that's my best guess at this point). This does not explain why this only is an issue on my local environment with the same code sets, but what else do I have to go off of?
Does anyone have any suggested things to be on the look out for while I sift through this file? Not really sure what to be looking for as far as errors are concerned. Rubymines inspection stuff converted all my double quotes to single quotes and doesn't really have anything else to complain about.
Thanks in advance,
Jake Smith
I am guessing it might as well be an syntactical error in the corresponding view page Home/index.html.haml .. I am suspecting there is unintended '-' in front of variable call. I tried to simulate a similar scenario in my rails platform and see following page on browser
undefined method `-#' for false:FalseClass
Correct lines of code
%h1 All Movies
= "filtervalue=#{#isFilterOld}"
= "Sortvalue=#{#isSortOld}"
Edited to simulate the error (observe the - in front of isFilterOld variable)
%h1 All Movies
= "filtervalue=#{-#isFilterOld}"
= "Sortvalue=#{#isSortOld}"
I have fixed the issue!
What fixed it:
Go to the directory where your gems are (for me that was C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1)
Delete all gems except for bundler
Make sure you delete the gems from the /cache/, /gems/, and /specifications/ folders (I just deleted them from the /gems/ folder at first and bundle install indicated that it could still find the gems)
Run bundle install
Further Inquiry:
Does anybody have any idea why this worked? I don't know if at this point I can narrow down which gem was causing the issue because the app is working now (I can visit all the urls with corresponding views). If the issue comes up again, I will delete gems one by one to nail down which one was at least causing the issue for me. But if anyone has any insight on this, a more detailed answer would be greatly appreciated by many more people than just me, I think. Thanks to all who helped thus far!

Rails Controller not picking up matching models and methods

So my Rails controller isn't working (properly) for some reason.
I first noticed something funny when I opened the controller file for the first time.
Compare this to normal syntax highlighting. (Also notice the overly long name)
This was the error I got when I tried to create a link in one of my views.
ActionView::Template::Error (undefined method `new_voyage_at_port_log_entries_path' for #<#<Class:0x007fb1c5921a98>:0x007fb1c81a32a0>):
Here's proof that I inserted this in my routes.
resources :voyage_at_port_log_entries
I do have it working by creating manual routes, but that is a little awkward, and I may forsee problems later. Why might ActionView not be working?
DUH! Routes are created for the singular version.
So...
new_voyage_at_port_log_entry_path
works!
BUT...syntax highlighting is still off...
Hmmm...not important but weird...probably has a different pluralization engine?

Rails 3.1. What's the easiest way to make chaining dropdown selects?

I was trying to make work this:
http://chainselects.hypermediasoft.com/
But got error:
Routing Error
uninitialized constant ChainSelectsHelper
So i have to make some break and ask community - is there any easy way to make chaining select boxes for my application forms?
UPDATE:
Maybe i should make editions in some config files? I can see thist ChainSelectsHelper in vendor/plugins/ChainSelects/lib/app/helpers/chain_selects_helper.rb. But why my application can't see this? Any assets pipeline configs needed?
And got this error in model:
undefined method `acts_as_chainable' for #<Class:0x007fe387542780>
From the looks of it, it seems that you did not add this in the controller:
include ChainSelectsHelper
Keep in mind that modifications have to be made to both model and controller, as stated here.

Resources