ActiveAdmin show partial doesn't see the model - ruby-on-rails

In ActiveAdmin 0.4.3, and Rails 3.2.2 I'm trying to customize the show screen of my Article mode
ActiveAdmin.register Article do
show do
render "show"
end
end
And in app/views/admin/articles/_show.html.haml
%div= article.description
But whenever I try to show an Article I get:
NoMethodError in Admin/articles#show
Showing /Users/phishman/Sites/wisegrowth/app/views/admin/articles/_show.html.haml where line #1 raised:
undefined method `description' for <article></article>
:Arbre::HTML::Article
Extracted source (around line #1):
1: %div= article.description
Trace of template inclusion: /Users/phishman/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.4.3/app/views/active_admin/resource/show.html.arb
Rails.root: /Users/phishman/Sites/wisegrowth
Application Trace | Framework Trace | Full Trace
app/views/admin/articles/_show.html.haml:1:in `_app_views_admin_articles__show_html_haml___3305533421865107600_2209712640'
app/admin/articles.rb:20:in `block (2 levels) in <top (required)>'
app/middleware/flash_session_cookie_middleware.rb:17:in `call'
Can you please help me on this? It is getting me crazy!
In the console everything seems to be working fine and if I do:
a = Article.last
a.description
=> "my article description"

Try this instead:
render :partial => "show", :locals => {:article => article }

Related

Submitting multipart form leads to internal server error on Rails 4.2

When submitting a simple multipart form, the server crashes and displays "Internal server error".
I have scaled down the form to the minimal:
<%= form_for #media_object, :html => {:multipart => true} do |f| %>
<%= f.file_field :media_object_image %>
<%= f.submit "Create!" %>
<% end %>
The log trace:
ERROR ArgumentError: unexpected prefix: {"RackMultipart"=>nil, ""=>nil}
/Users/christer/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tmpdir.rb:111:in `make_tmpname'
/Users/christer/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tmpdir.rb:129:in `create'
/Users/christer/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tempfile.rb:132:in `initialize'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/multipart/parser.rb:22:in `new'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/multipart/parser.rb:22:in `block in create'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/multipart/parser.rb:135:in `get_current_head_and_filename_and_content_type_and_name_and_body'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/multipart/parser.rb:59:in `block in parse'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/multipart/parser.rb:56:in `loop'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/multipart/parser.rb:56:in `parse'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/multipart.rb:25:in `parse_multipart'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/request.rb:375:in `parse_multipart'
/Users/christer/.rvm/gems/ruby-2.3.0#teamhubs4/gems/rack-1.6.4/lib/rack/request.rb:207:in `POST'
Googling around turns up multipart submission problems with Rails 4.2 due to maximum number of open multipart files, but this is definitely different.
I'm running Rails 4.2.6 with Ruby 2.3.
Although I'm not using the imgur gem, Phil Ross put me on the right track. I do indeed extend the Array class with a to_hash method. Removing this extensions, and voila!, things work as they should.
imgur is not alone. dropbox gem is also known to cause this. Check your Gemfile.

Error NoMethodError in Questions#index in Shapado (Ruby on Rails)

I am newbie with Shapado. I’m trying to install shapado in my laptop (MAC OS) and when I try to access to http://localhost.lan:3000 I have the following error:
NoMethodError in Questions#index
Showing /Users/sciruela/Documents/shapado/shapado/app/views/shared/_login_drop_down.html.haml where line #10 raised:
undefined method `[]' for nil:NilClass
Extracted source (around line #10):
7: = link_to provider.titleize, '/users/auth/facebook', :class => 'auth-provider Facebook', :id => 'facebook'
8: - else
9: %li
10: = link_to provider.titleize, multiauth_url(provider), :class => "auth-provider #{provider}", :id => dprovider
11:
12: -if current_group.allow_any_openid
13: %li
Trace of template inclusion: app/views/shared/_login_menu.html.haml, app/views/shared/_topbar.html.haml, app/views/layouts/application.html.haml
Rails.root: /Users/sciruela/Documents/shapado/shapado
Application Trace | Framework Trace | Full Trace
app/views/shared/_login_drop_down.html.haml:10:in `block in _app_views_shared__login_drop_down_html_haml__1123238317393261506_2159776840'
app/views/shared/_login_drop_down.html.haml:2:in `each'
app/views/shared/_login_drop_down.html.haml:2:in `_app_views_shared__login_drop_down_html_haml__1123238317393261506_2159776840'
app/views/shared/_login_menu.html.haml:6:in `_app_views_shared__login_menu_html_haml___434956048083202339_2193663100'
app/helpers/application_helper.rb:36:in `multiauth_dropdown'
app/views/shared/_topbar.html.haml:21:in `_app_views_shared__topbar_html_haml___2782218627514502243_2204427320'
app/views/layouts/application.html.haml:10:in `block in _app_views_layouts_application_html_haml___4514694021451724572_2205033860'
app/helpers/layout_helper.rb:74:in `call'
app/helpers/layout_helper.rb:74:in `block in ie_tag'
app/helpers/layout_helper.rb:72:in `ie_tag'
app/helpers/layout_helper.rb:79:in `ie_html'
app/views/layouts/application.html.haml:2:in `_app_views_layouts_application_html_haml___4514694021451724572_2205033860'
app/controllers/application_controller.rb:122:in `block (2 levels) in find_questions'
app/controllers/application_controller.rb:121:in `find_questions'
app/controllers/questions_controller.rb:67:in `index'
lib/sso_strategy.rb:18:in `call!'
app/middlewares/dynamic_domain.rb:17:in `call'
Request
How I could solve it?
Thanks
In Rails, the [] acts as a reader and []= as a setter. It looks like the issue is occurring on line 10 at multiauth_url(provider).
It also appears that provider is nil in this case. I suggest using pry (a gem) and drop in binding.pry to debug further. You might be making the assumption that a provider always exists, so verify that provider is not nil first.
did you follow shapado's Readme? seems like you did not this step
https://github.com/ricodigo/shapado/blob/master/README#L25

Understanding RSpec Failure

I'm getting these failures when running rspec spec/. The spec that is failing is was auto-generated with the scaffolding. I'm trying to understand RSpec but I don't know where to begin looking for the cause other than it feels like some method is missing?!? Yet, app appears to be working fine. Nothing about these failures appears in test.log. Is there another place I should be looking for hints to track this down?
$ rspec spec/
.....................F.F.
Failures:
1) clowns/edit.html.haml renders the edit clown form
Failure/Error: render
undefined method `to_sym' for nil:NilClass
# ./app/views/clowns/_form.html.haml:4:in `block in _app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
# ./app/views/clowns/_form.html.haml:1:in `_app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
# ./app/views/clowns/edit.html.haml:3:in `_app_views_clowns_edit_html_haml___574620942879655923_2176081980_599706797287605391'
# ./spec/views/clowns/edit.html.haml_spec.rb:13:in `block (2 levels) in <top (required)>'
2) clowns/new.html.haml renders new clown form
Failure/Error: render
undefined method `to_sym' for nil:NilClass
# ./app/views/clowns/_form.html.haml:4:in `block in _app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
# ./app/views/clowns/_form.html.haml:1:in `_app_views_clowns__form_html_haml__3590088286240866241_2176114460_3896491916910336970'
# ./app/views/clowns/new.html.haml:3:in `_app_views_clowns_new_html_haml__1085372210838170129_2159651900_599706797287605391'
# ./spec/views/clowns/new.html.haml_spec.rb:12:in `block (2 levels) in <top (required)>'
Finished in 1.03 seconds
27 examples, 2 failures, 2 pending
And here is the spec that apparently fails (edit.html.haml_spec.rb). It was auto-generated by rails g scaffold Clown name:string balloons:integer:
#spec/views/clowns/edit.html.haml_spec.rb
require 'spec_helper'
describe "clowns/edit.html.haml" do
before(:each) do
#clown = assign(:clown, stub_model(Clown,
:name => "MyString",
:balloons => 1
))
end
it "renders the edit clown form" do
render
# Run the generator again with the --webrat-matchers flag if you want to use webrat matchers
assert_select "form", :action => clown_path(#clown), :method => "post" do
assert_select "input#clown_name", :name => "clown[name]"
assert_select "input#clown_balloons", :name => "clown[balloons]"
end
end
end
Are you also using simple_form (or perhaps even formtastic)? I get the same error when I convert the scaffold forms from standards forms to simple_form forms (form_for(#user) => simple_form_for(#user)).
It still works, as you say, so I'm not sure it's worth worrying about. I think you'd be better off just letting Cucumber worry about it. Sarah Mei says view specs are a waste of time. :-)

Setting up devise / mongomapper on Rails 2.3.8

I am trying to get basic authentication working using devise and mongomapper.
Following the instructions here:
http://johnwyles.com/2010/03/15/sessions-in-mongodb-using-mongomapper-and-devise/
(except deferring the routes.rb changes until after the generators are run to address errors)
I got it as far as getting the following paths to work:
/users/sign_up ::
/users/sign_in ::
/users/password/new ::
/users/confirmation/new
However, just trying to hit "/" gives me an error
NameError in UserController#sign_in
uninitialized constant UserController
RAILS_ROOT: /Users/bentrevino/Documents/Dev/devisetest
Application Trace | Framework Trace | Full Trace
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:443:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:92:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:364:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `each'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:444:in `recognize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.8/lib/action_controller/routing/route_set.rb:437:in `call'
After I submit a sign-up request, I get this error
RuntimeError in Registrations#create
Showing /Library/Ruby/Gems/1.8/gems/devise-1.0.8/app/views/devise_mailer/confirmation_instructions.html.erb where line #5 raised:
Missing host to link to! Please provide :host parameter or set default_url_options[:host]
Extracted source (around line #5):
2:
3: <p>You can confirm your account through the link below:</p>
4:
5: <p><%= link_to 'Confirm my account', confirmation_url(#resource, :confirmation_token => #resource.confirmation_token) %></p>
Does anybody know what might be going on here?
Thanks!
Ben....
At least one issue you are having is that you have not created a controller for your root route that you specified in config/routes.rb file. Run a call to rails generate controller [name] to make a new controller. Then specify that name in your config/routes.rb file for our root route.

Why I got an error if I named my controller as "leaves" in Ruby on Rails

The scaffold command is the following
ruby script\generate scaffold Leave employee_id:integer leave_type_id:integer date:date
I know I could change the name but I just wonder why it always throws undifined new_leave_path
Glad to know your brilliant thoughts.
Below is the full details of the error:
NameError in Leaves#index
Showing app/views/leaves/index.html.erb where line #26 raised:
undefined local variable or method `new_leave_path' for #<ActionView::Base:0x620ea70>
Extracted source (around line #26):
23:
24: <br />
25:
26: <%= link_to 'New leave', new_leave_path %>
Application trace:
app/views/leaves/index.html.erb:26
app/controllers/leaves_controller.rb:7:in `index'
rake routes
new_leafe_path
or
map.resources :leaves, :singular => :leave
)
#insic Hi
It is just working fine on my machine. may be there are some conflicts with any gem or plugin that you might be using. Can't explicitly find out what is the exact reason, as I am a newbie to rails.
Add
#routes.rb
map.resources :leaves

Resources