Rails 4 undo "rails destroy MODEL" - ruby-on-rails-4

I was installing Devise into my Rails 4 application and misread the line in the wiki that talks about generating devise as a new model. I thought I needed to add it to each of my existing models. I used "rails g devise messages" to install devise in my messages model then realized that I was doing it wrong. So I used rails g devise messages to remove devise. This command got rid of my messages model entirely (the model that the whole app is built around). I have looked all over for how to reverse this but can't seem to find anything. I tried running rake db:rollback but it only rolled back my previous installs.
PLEASE tell me that there's some way to retrieve the model, views, controller and 300+ entries!
Thanks for the help!

Related

Setting up a blog on AWS Cloud9

I'm new to programming, and i've been following the upskill course for about 2 weeks now. Everything was going great untill yesterday. I started the Deep Dive: Build a Blog section that uses Cloud9 and Ruby to build a blog. I have tried many times to follow the exact same path as the instructor but i keep on having the same problem.
The commands that I input in the terminal are the following (I do this on a new environment with the default settings).
$ rails new blog
Then the instructor ask us to change the 'sqlite3' line in the file called "gemfile" into gem 'sqlite3', '1.3.13'. To use the same version as him.
I then inpunt :
cd
cd environment
cd blog
bundle install
bundle update
rails generate scaffold Post title:string body:text
rake db:migrate
rails server
It is at this point that the problem occurs. The instructor terminal's response 3 more lines that i don't have . In my case the output stops at Ctrl c to shut down.
Plus after that the instructor click preview running application and is sent to the "ruby welcome page". He then get rid of a part of the URL to go to the blog. In my case the URL is completely different from his, it looks like that https://c187d78accd944209c8f91023e991d71.vfs.cloud9.us-east-2.amazonaws.com/ (actual URL). and his like that
Please help to solve this i can not see anything in preview page.
Do you guys know what I've been doing wrong ?
Thank you for reading all of these it's my first time posting so i hope it's kind of understandable.
Have a great day
I am trying to solve this problem but i can't solve this.
please help me why i am not see anything in preview page ?

active job in rails 4

I am looking forward to active job for active record for rails 4. I search related to it. I found gem 'delayed_job_active_record' . But this supports Rails 3+.
In that I want to run the job everyday at some specific time to check the due date. If due date reached, before some particular period Want to send alert message/mail. And I am using devise for authentication.
And also I see the gem 'devise-async-activejob'. Is this affect my authentication system? Which gem can I use for this scenario without affecting my existing features. Suggest any Guide or documentation or sample.
Thanks.
Set the queue_adapter in config/application.rb
config.active_job.queue_adapter = :delayed_job
See the rails guide for more details.
See
http://edgeguides.rubyonrails.org/active_job_basics.html
https://blog.codeship.com/how-to-use-rails-active-job/

Running rails app both as engine and app

I'm transforming a Rails application (say appA) into engine so that I can hook it into another Rails app (say appB). However appA must run as a Rails app solely as well. That's because a customer can buy
appA or
appB with appA. There is no option of buying only appB.
Following rails oficial guide I made (among others) following changes:
Changed Rails.application.routes.draw to ActionPlan::Engine.routes.draw in routes.rb.
Created lib/action_plan/engine.rb with content shown below:
module ActionPlan
class Engine < ::Rails::Engine
isolate_namespace ActionPlan
end
end
Now when I run rails s I get /action_plan/config/routes.rb:1:in '<top (required)>': uninitialized constant ActionPlan::Engine (NameError).
I guess I should initialize ActionPlan::Engine in application.rb file somehow but I don't know how neither whether it's the way to go.
So is it possible to build an app/engine in rails such as appA? If it is, how can I overcome that problem?
After some researching and talking to some friends, I found out that it's not possible to do such a think with rails, but it's possible you to create another rails app (say appC) and use it only to run your engine, i.e appC is a silly rails app used only to make it possible to run your engine.

Ruby gem or snippet to use different ActiveRecord db connection depending on model attribute value

Can you suggest a ruby gem or show a snippet with exsmple how to make AtiveRecord::Base successor to choose a db connection depending on a model record id?
Ok. Please let me know if the following solution can work if not then I will delete it from here.
I wouldn't use Gem for this.
Here a mud map how I would tackle this project. ( for small to medium projects only )
Ruby Class: manages all the connections.
Query handler: dictates what connection do we need based on the
condition.
Connector is a simple class that grabs stuff from
Rails and trigger the query handlers.
Query handler is the optional bit. You can connect your Rails directly to the Ruby Class. ( I don't like this as they will be coupled a bit too much )
Have your database.yaml file (just to keep Rails happy) Your application will be using the Ruby Class connector and query handler to grab stuff from different databases, No Rails needed there.
Hope this help!
PS: Again if you think this is not good solution let me know and I see what I can do. Cheers mate.

cancancan and devise testing for rails app

I've been researching how to test my Ability and Users for a small test rails wiki i'm building and i'm having difficulty wrapping my brain around how to test either or both ?.
I think i'd like to sign_in a user as admin/editor etc. and test that user behaves like it should. I'd like to also test that Pages are displaying the correct information for an authenticated user.
This is more then one problem and i'm looking for some basic nudging less then an answer :).
I use Rspec, Cancancan, Rails 4 and devise for authentication.
I've read up on a few ways none of which worked for me:
Cancan example
Another ex i tried for cancan
Devise and rails 4 I'm using route authentication for devise.
Devise and sign_in
In any case here are my files. I'll just link to my git repo
my abilities.rb
pages.rb
users.rb
pages_controller.rb
I have factories as well but what's the trick to doing the following
Signing in users: The examples suggest using the devise test helpers then creating a signed_in user stub. I haven't quite succeeded at this yet :( so a nudge in the right direction
Devise and abilities: My understanding is I need to use the cancan/matchers then make some factories for admin/editor or any views and then do my usual tests once i've logged in a user and instantiated abilities. also failed at all the examples I tried.
Finally testing the controller for pages: I required again logging in the user with the correct ability and then testing each action for each users to see if i received the correct records back?
Maybe i'm not separating out the roles enough or i'm missing some important steps from what I could read but even a small nudge on any of these would be much appreciated.
You may have seen this, but this CanCan page https://github.com/ryanb/cancan/wiki/Testing-Abilities describes some basic high-level methodology behind testing the ability class. TL;DR Focus heavily on testing the Ability class itself and keep the controller tests light.