No route matches POST when updating rails-api gem - ruby-on-rails

When I add this to my gem file ( rails 4.0.1 )
gem 'rails-api', git: 'https://github.com/rails-api/rails-api.git', branch: 'master'
My routes seem to break (although rake routes is the same before/after)
I get this after I attempt to update a simple scaffold model
No route matches [POST] "/surveys/1" when I update a record
by commenting out this gem it works again - any ideas what I did wrong?
thanks!
PS: Adding this to gem file so I can use strong parameters to follow railscasts#196 in rails 4

Adding this to gem file so I can use strong parameters to follow
railscasts#196 in rails 4
Perhaps your app is having a problem with what you're using this gem for. I don't know if you've just upgraded to Rails 4, but the latest version uses Strong Params by default
The Railscast seems to be involved with loading nested forms. We do this all the time without the rails-api gem - can you let us know what you're trying to use this gem for specifically?

Related

Rails bootstrap gem monkeypatching method not working

I'm using the excellent twitter-bootstrap-rails gem. There is a helper within that gem (NavbarHelper) which is used to generate Bootstrap navbars with a Ruby helper. I want to monkey patch the gem such that the dropdown lists won't have carets.
So, I looked into the source and found the relevant method here. All I have to do is override it. I created a new file in config/initializers called navbar.rb with the following content:
NavbarHelper.module_eval do
def name_and_caret(name)
"HELLO WORLD"
end
end
Presumably, all of the dropdown titles then should be rendered as "HELLO WORLD" in my app (as referenced by the gem source). However, this is not occurring, and the gem does not appear to be monkeypatched at all.
I tried placing puts NavbarHelper.methods - Object.methods in the initializers file, and there were no results, which makes me think that Rails is not loading the gem correctly before the initializers. I have also checked and verified that the gem is not using autoload for its helpers.
Edit
What may be complicating this is the fact that my Gemfile includes the gem in the following manner:
gem 'twitter-bootstrap-rails', git: 'git://github.com/seyhunak/twitter-bootstrap-rails.git', branch: 'bootstrap3'
I'm not sure if this specific versioning means the monkeypatching doesn't work.
Edit #2
It seems there is only one version of the gem on my system, so I don't think that's the issue. Also, I have tried placing require 'twitter-bootstrap-rails at the top of the initializers file, with no results.
The problem is that you patch the method on this module but the module already got included at this point. Try to define this in your application_helper.rb
def name_and_caret(name)
super("blub #{name}")
end

unable to solve the routing error while using devise gem

I am using devise gem, I had install the gem also but I am still getting error as below:
no route matches[Get] "/dhwani_app"
In your routes try adding
"devise_for :(whatever your model is)" but obviously don't put the quotations in

ruby gem that prepares data for datatables

I'd like to use datatables in my rails application but I'd like to avoid prepraring JSON data by myself, so I'm looking for a gem that does it. Ideally I'd pass an ActiveRecored Relation and the gem generated JSON that could be consumed by datatables, for example:
class ItemsController < ApplicationController
def index
# I fetch data I need (taking into account authorization, search etc.)
#items = Item.find_relevant_items
respond_to do |format|
# gem prepares JSON for datatables
format.json { ItemDatatable.new(#items) }
# ...
end
end
end
I'm aware that there are several gems availabe. However, they don't suit me: jquery-datatables-rails is just a wrapper for the JS and the others seem to be outdated or not maintained (ajax-datatables-rails, rails_datatables, simple_datatables).
Do you know about any gem that would serve data for datatables?
Ruby's JSON module is built-in, just require 'json' at the top of a Ruby script to make it available. See "How do I parse JSON with Ruby on Rails?" for more information.
Rails also includes JSON capability too. See "Understanding Ruby and Rails: Serializing Ruby objects with JSON" for info using JSON and Rails. Rails is a fast-moving platform so that might be a bit out of date, but it should get you started. "Lightning JSON in Rails" is a good read for things to pay attention to as you generate JSON.
"JSON implementation for Ruby" is a great reference for Ruby and JSON also.
The best way I have found to using datatables in a rails app is this:
jquery-datatables-rails gem to get all the assets datatables needs
ajax-datatables-rails gem to get the the JSON datatables expects when using server side pagination and searching.
There are other gems that make it easier to generate the JSON datatables need If you don't want to go through the trouble of making a new class like in the RailsCast. You can find them here
RABL and JBuilder both spring to mind.
They are json template handlers and awesomely simple to use and both are equally powerfull enabling complete customisation of your json output.
There are railscasts on them both
http://railscasts.com/episodes/320-jbuilder
http://railscasts.com/episodes/322-rabl
and the sites
https://github.com/rails/jbuilder
https://github.com/nesquena/rabl
Both are well maintained.
Otherwise the datatables-rails gem is really the best option for you
http://railscasts.com/episodes/340-datatables?view=asciicast
UPDATE 2
It's the gem you have already looked at
As per railscast the gem is defined in the Gemfile
group :assets do
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-ui-rails'
end
I strongly urge you to watch that railscast (http://railscasts.com/episodes/340-datatables?view=asciicast) as there are other configurations needed.

datatables with rails issue

I have included this in my rails:
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
but when I start the server I'm getting this error :
←[31mYou passed :github as an option for gem 'jquery-datatables-rails', but it is invalid.←[0m
I guess its because I'm running it locally.BTW,what will be my path if I'm running it locally?
1 more thing I followed this cast:
http://railscasts.com/episodes/340-datatables?view=asciicast
I have also tried simply this:
gem 'jquery-datatables-rails'
But after bundle install the css and js files are not downloaded and it is giving me file not found error.
Check the cast:
The github option is new in Bundler 1.1. If you don’t have this you’ll
need to pass in the full git path instead.
So try to use
gem 'jquery-datatables-rails', git: 'https://github.com/rweng/jquery-datatables-rails.git'
Difficult to say why your table is hidden without the view and associated javascript code.
Check if you call the dataTable() function on the correct table DOM element.
Also check for any fancy parameters in the call.
If that checks out, post the code for more help.

Rails Application templates remove a default gem

When using a rails application template is possible to make so that some default gems (sqlite3, coffescript and sass) are not included in the Gemfile?
I'm sure you've solved this problem in the last 7 years, but for everyone else, the best method I've seen for doing this is to gsub it out of the file:
# Removes sqlite3, coffee-rails, and sass-rails gems
gsub_file "Gemfile", /^gem\s+["']sqlite3["'].*$/,''
gsub_file "Gemfile", /^gem\s+["']coffee-rails["'].*$/,''
gsub_file "Gemfile", /^gem\s+["']sass-rails["'].*$/,''
Yes, just modify your application template file to not include them.
take a look https://github.com/RailsApps/rails3-application-templates
to get a better idea, specifically mongoid templates

Resources