Active admin not finding partial in show - ruby-on-rails

This should be pretty simple, trying to render a partial on active admin in show action:
Object name is: Listing
ActiveAdmin.register Listing do
show do
attributes_table do
row :foo
row :bar
render 'map'
end
end
end
I added the partial under app/admin/listings/_map.html.haml
I get the no template found error:
Missing partial admin/listings/_map, active_admin/resource/_map, active_admin/base/_map, inherited_resources/base/_map, application/_map with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :haml, :jbuilder]}.
Also tried adding here: app/admin/_map.html.haml and admin/listings/_map.html.haml
And tried: moving the render outside the attributes_table, like so:
show do
render 'map'
attributes_table do
row :foo
row :bar
...
On rails', '4.1.9', 'activeadmin', '~> 1.0.0.pre1'

Your view should be put into views directory:
app/views/admin/listings/_map.html.haml
Rendering partial should look as follows:
show do
render partial: 'map'
# ...
end

Related

templates missing with mailer

I am new to using mailer and read a few tutorials but can't for the life of me work out why this this error is appearing
Missing template layouts/mailer with {:locale=>[:en], :formats=>[:text], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :haml]}. Searched in:
* "/Users/paulmcguane/RoR/barista/app/views"
* "/Users/paulmcguane/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/devise-3.5.6/app/views"
new_record_notification.text.erb
Hi,
A new record has been added: <%= #record.name %>
Thanks
model_mailer.rb
class ModelMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.model_mailer.new_record_notification.subject
#
def new_record_notification(record)
#record = record
mail(to: 'email#address') do |format|
format.text
end
end
end
Most likely you use layout 'mailer' in your ApplicationMailer class. Use existing layout or don't use layout at all.

Rspec missing template error - html+phone.slim (variants) - how to?

I have a view with the following format:
show_map.html+phone.slim
I am testing my controller, expecting my test to render that template , does anyone know the proper syntax for rendering a view with variant ?
This is what I am trying:
describe "show_map action" do
it "renders show map view" do
get :show_map, {:id=>#job.id,:format=>:html,:variants=>:phone}
expect(response).to render_template('show_map')
end
also tried
get :show_map, {:id=>#job.id,:format=>'html.phone'}
Either way, I get a missing template error:
JobsController show_map action renders show map view
Failure/Error: get :show_map, {:id=>#job.id,:format=>:html,:variants=>:phone}
ActionView::MissingTemplate:
Missing template jobs/show_map, application/show_map with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :slim]}
Anyone know how to do this?

Rails respond with JBuilder (AngularJS)

i have a simple application to snooker league and i have a action add_player in LeaguesController. My client (AngularJS) call this action and i want to respond with json format using JBuilder. This working fine:
def add_player
...
render :json => #league.players.to_json(:only => [ :id, :firstname, :lastname, :max_break, :email ])
end
But when i delete this line and add:
respond_to do |format|
format.html
format.json
end
i have this error:
ActionView::MissingTemplate (
Missing template leagues/add_player,
application/add_player
with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder, :haml]}.
Searched in:
* "/home/daniel/SitesWWW/snookerLeague/app/views"
):
app/controllers/leagues_controller.rb:67:in `add_player'
Of course i have file add_player.json.jbuilder:
json.players #league.players do |player|
json.id player.id
json.firstname player.firstname.capitalize if player.firstname
json.lastname player.lastname.capitalize if player.lastname
json.email player.email
json.max_break player.max_break
end
So, what i should do?
Notice in your error message :formats=>[:html] this indicates to me it is trying to render add_player.html.erb and not your jbuilder template.
To verify this, try changing the calling code and append .json to the url which will force the format to be json.
You can also specify a default of json on your routes and not include it in the url:
resources :leagues, defaults: { format: :json } do
member do
post :add_player
end
end
see also: http://guides.rubyonrails.org/routing.html#defining-defaults

where to store a jbuilder template?

I'm attempting to use a jbuilder template.
Given the controller,
class Api::ReviewsController < ApplicationController
before_filter :authenticate_user!
respond_to :json
def create
#review_request = ReviewRequest.new(review_request_params.merge(user_id: current_user.id))
if #review_request.save
render 'review_requests/review'
else
head :forbidden
end
end
end
and I have the jbuilder template stored at app/views/review_requests/review.json.jbuilder
json.review_request do
json.(#review_request, :title,)
end
I'm getting a template note found error.
ActionView::MissingTemplate (Missing template review_requests/review with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/jd/Dropbox/application-code/antipattern/app/views"
* "/Users/jd/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/devise-3.4.1/app/views"
* "/Users/jd/Dropbox/application-code/antipattern"
* "/"
):
app/controllers/api/reviews_controller.rb:8:in `create'
Any thoughts on either where the correct place to store this template is or why rails isn't finding the template i'm using (if the storage location happens to be ok)?
jbuilder needs a json type web request, an html request to a rails server will cause the jbuilder template to not be rendered.

Rails: render value without view

i've a problem
i'm trying to make an action method like this
def webm
#url = Video.find(params[:id]).avatar.url(:webm_sd)
end
and i just want to return the #url value without using view .. it will return string url i need it to be rendered where ever the method get called
it gives me error
Missing template api/v1/videos/webm, application/webm with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
and even if i add some views in videos folder it still gives me the same error!
what should i do?
You can use proper renderer
render json: #url
or to render just string
render text: #url

Resources