Issue with Application View Koudoku and Instance Variable - ruby

In my application I have created a contact form in the footer of the page and hence it's been placed within the application layout. I have also set up Koudoku to manage my stripe payments on the site.
Via the Koudoku documentation it says since Koudoku uses the application layout all paths must be prefixed with main_app.
This has been implemented for all the links already, however the contact form is using a instance variable declared in the application controller like this.
def set_contact
#contact = Contact.new
end
and the form in the application view looks like this
<%= form_for #contact do |f| %>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :comments %>
<%= f.text_area :comments, class: 'form-control' %>
</div>
<%= f.submit 'Submit', class: 'btn btn-default' %>
<% end %>
I am getting this error here
undefined method `contacts_path' for #<#<Class:0x007f8b4d6bb658>:0x007f8b5033fc88>

Related

Problem with radio button tag ruby ​on rails

I am developing a simple account registration and update form and I have recently entered a parameter that can have two possible choices, in my case one problem occurred:
Problem:
<div class="tag">
<%= f.label :ruolo %><br />
<%= f.radio_button_tag(:ruolo, "admin") %>
<%= f.label_tag(:ruolo_admin, "admin") %>
<%= f.radio_button_tag(:ruolo, "user") %>
<%= f.label_tag(:ruolo_user, "user") %>
</div>
if I leave the code like this it gives me an error like:
NoMethodError in Devise::Registrations#edit
undefined method `radio_button_tag 'for # <ActionView :: Helpers :: FormBuilder: 0x00007fd6fd02f478>
this is the form:
<div class="row">
<div class="col s12 l6 offset-l3">
<br>
<br>
<h4 class="center">Registrazione</h4>
<br>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name, autofocus: true %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email %>
</div>
<div class="field">
<%= f.label :ruolo %><br />
<%= f.radio_button_tag(:ruolo, "admin") %>
<%= f.label_tag(:ruolo_admin, "admin") %>
<%= f.radio_button_tag(:ruolo, "user") %>
<%= f.label_tag(:ruolo_user, "user") %>
</div>
<div class="field">
<%= f.label :password %>
<% if #minimum_password_length %>
<em>(<%= #minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<br>
<div class="actions">
<%= f.submit "Iscriviti", class: "waves-effect waves-light btn btn-devise" %>
</div>
<br>
<% end %>
<%= render "devise/shared/links" %>
</div>
</div>
Controller code:
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
#roles=Role.all
devise_parameter_sanitizer.permit(:sign_up, keys: [:name,:ruolo])
devise_parameter_sanitizer.permit(:account_update, keys: [:name,:ruolo])
end
end
radio_button_tag is not an instance method of ActionView :: Helpers :: FormBuilder, but rather ActionView::Helpers::FormTagHelper
So instead of calling it like:
<%= f.radio_button_tag(:ruolo, "admin") %>
You simply call it like:
<%= radio_button_tag(:ruolo, "admin") %>
For more details on this method please check the docs:
https://apidock.com/rails/v6.0.0/ActionView/Helpers/FormTagHelper/radio_button_tag

Nested Resources in Rails 4

Im attempting to create a Rails app that manages temperatures for a garden. I have setup my controllers and models appropriately to have resources for Grow - Tray - Plant.
Grow has many trays
Tray has many Plants
Im able to create nested trays in each grow. But I am not able to create plants in a designated tray.
The github repo
Im getting the following error:
undefined method `tray'
This is for my plant _form
<%= form_for([#grow, #grow.tray.plants.build]) do |f| %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :tray_id %><br>
<%= f.text_field :tray_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
The routes look as such:
resources :grows do
resources :trays do
resources :plants
end
end
The form for building the tray looks like this and it works:
<%= form_for([#grow, #grow.trays.build]) do |f| %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :grow_id %><br>
<%= f.text_field :grow_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Is this even the right approach?
If Grow has_many trays, then #grow.tray would be undefined (note the singular).
Perhaps you should assign the relevant Tray in the controller, so it can be referenced in the view appropriately:
#tray = #grow.trays.find(...)
I'd also recommend avoiding nesting routes more than two levels. Forms like these tend to be more difficult to manage with multiple nesting.

simple_form is blank for sign-in but formatted properly for sign-up

I am working through adding simple_form formatting to simple sign-in and sign-up forms.
While the sign-up form is formatting properly - the sign-in form has no inputs?
Sign-in form
My code is available on github (here) with the most recent version pushed which includes this error. Any ideas for a newbie?
Replace <% with <%= next to the f.input statement.
<h2>Sign in</h2>
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: { class: 'form-horizontal'}) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :remember_me, as: :boolean %>
<div class="form-actions">
<%= f.submit "Sign in", class: "btn btn-primary" %>
</div>
<% end %>
<%= render "devise/shared/links" %>

Fields_for Nested Model Rails 3.2.2

I have some nested models in my Rails application.
i have an article hat has mny properties.
class Article < ActiveRecord::Base
has_many :properties, :dependent => :destroy
accepts_nested_attributes_for :properties
end
class Property < ActiveRecord::Base
belongs_to :article
end
And now i want to edit this in my View so I editet the controler
# GET /articles/new
# GET /articles/new.json
def new
#article = Article.new
3.times { #article.properties.build }
respond_to do |format|
format.html # new.html.erb
format.json { render json: #article }
end
end
And also edited the View and the _format.html.erb
<%= form_for(#article) do |f| %>
<% if #article.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#article.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% #article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br />
<%= f.text_area :description %>
</div>
<% f.fields_for :properties do |prop| %>
<div class="field">
<%= prop.label :name %><br />
<%= prop.text_field :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
But there is no way to show up. If i want to create a new Model, i can not see any input fields for the properties.
What have i do wrong?
You're missing an = in your fields_for line. That is, it should be:
<%= f.fields_for :properties do |prop| %>

Unable to use paperclip with rails 3.1

I'm trying to use paperclip with rails 3.1 but I keep getting this routing error.
No route matches {:action=>"show", :controller=>"users"}
I followed the instructions at thoughtbot/paperclip on github.
<%= form_for :user, #user, :url => user_path, :html => { :multipart => true } do |f| %>
<% if #user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% #user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :FirstName %><br />
<%= f.text_field :FirstName %>
</div>
<div>
<%= f.label :avatar%>
<%= f.file_field :avatar %>
</div>
<div class="field">
<%= f.label :LastName %><br />
<%= f.text_field :LastName %>
</div>
<div class="field">
<%= f.label :Email %><br />
<%= f.text_field :Email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
User.rb
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
routes.rb
City::Application.routes.draw do
resources :users
end
show.html.erb
<p id="notice">
<%= notice %>
</p>
<p>
<b>Firstname:</b>
<%= #user.FirstName %>
</p>
<p>
<b>Lastname:</b>
<%= #user.LastName %>
</p>
<p>
<b>Email:</b>
<%= #user.Email %>
</p>
<p>
<b>Avatar</b>
<%= image_tag #user.avatar.url %>
<%= image_tag #user.avatar.url(:medium) %>
<%= image_tag #user.avatar.url(:thumb) %>
</p>
<%= link_to 'Edit', edit_user_path(#user) %> |
<%= link_to 'Back', users_path %>
!UPDATE!
$ rake routes
events GET /events(.:format) {:action=>"index", :controller=>"events"}
POST /events(.:format) {:action=>"create", :controller=>"events"} new_event GET
/events/new(.:format) {:action=>"new",
:controller=>"events"} edit_event GET /events/:id/edit(.:format)
{:action=>"edit", :controller=>"events"}
event GET /events/:id(.:format) {:action=>"show", :controller=>"events"}
PUT /events/:id(.:format) {:action=>"update", :controller=>"events"}
DELETE /events/:id(.:format) {:action=>"destroy", :controller=>"events"}
root / {:controller=>"events", :action=>"index"}
/:controller(/:action(/:id(.:format)))
I believe you should use users_path (plural) and, the user routes are not in your rake output, can you check your routes file?
The error you are having is not from paperclip cos paperclip has nothing to do with that error message you are having. check your routes very well and also try to restart you sever.

Resources