ActionView::MissingTemplate in Spree::Home#index - spree

I was trying to remove spree fancy. And when i tried to load the site i got this error.
ActionView::MissingTemplate in Spree::Home#index
Showing /var/www/mystore/app/views/spree/home/index.html.erb where line #2 raised:
Missing partial spree/home/slider, spree/store/slider, spree/base/slider, application/slider with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :rabl], :versions=>[:v1]}. Searched in:
* "/var/www/mystore/app/views"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/bundler/gems/spree_auth_devise-81a0fbb2db15/lib/views/backend"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/bundler/gems/spree_auth_devise-81a0fbb2db15/lib/views/frontend"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/gems/devise-3.2.4/app/views"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/bundler/gems/spree_gateway-ea9dd0468485/app/views"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/gems/spree_frontend-2.2.2/app/views"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/gems/spree_backend-2.2.2/app/views"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/gems/spree_api-2.2.2/app/views"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/gems/spree_core-2.2.2/app/views"
* "/home/spree/.rvm/gems/ruby-2.0.0-p481/gems/kaminari-0.15.1/app/views"
Extracted source (around line #2):
1 <% content_for :subheader do %>
2 <%= render 'slider' %>
3 <% end %>
But localhost:3000/products is working perfectly fine. Only the index page is not working.

spree_fancy overrides the home/index view. Seems you did not replace that one for the default.
Check that https://github.com/spree/spree_fancy/blob/master/app/views/spree/home/index.html.erb has thn reporting lines
<% content_for :subheader do %>
<%= render 'slider' %>
<% end %>
But https://github.com/spree/spree/blob/master/frontend/app/views/spree/home/index.html.erb doesn't

Related

No route matches [POST] "/basic_pages/basic_pages/home"

So I would simply like to post to my root. My problem is that if I try to do it the second time (first time works fine) I am posting /basic_pages/basic_pages/home instead of /basic_pages/home. Why does that happen and how do I fix this?
home.html.erb:
<h1>BasicPages#home</h1>
<p>Find me in app/views/basic_pages/home.html.erb</p>
<%= form_tag ('basic_pages/home') do %>
<%= text_field_tag :my_input %>
<%= submit_tag "Send input" %>
<% end %>
routes.rb
Rails.application.routes.draw do
root 'basic_pages#home'
post 'basic_pages/home'
get 'about' => 'basic_pages#about'
end
Hope this provides all the information necessary.
Instead of using form_tag ('basic_pages/home') use form_tag ('/basic_pages/home'). When you have posted the url is getting changed to /basic_pages/home, and then the form is again posting to /basic_pages/basic_pages/home, because of the relative path given to the form.
Try this
Rails.application.routes.draw do
post '/' => "basic_pages#home", as: "root"
get 'about' => 'basic_pages#about'
end
home.html.erb:
<%= form_tag ('/') do %>
<%= text_field_tag :my_input %>
<%= submit_tag "Send input" %>
<% end %>

rails 4 ransack gem, undefined path error

I have rails 4 app with an Events model that I want to make searchable on a variety of fields using the Ransack gem.
my controller action:
def index
#search = Event.ransack(params[:q])
#events = #search.result(distinct: true)
end
my search form in index.html.erb:
<%= search_form_for #search do |f| %>
<%= f.text_field :name_cont, class: "radius-left expand", placeholder: "Event Name" %>
<% end %>
However, in loading the page, I get the following error:
ActionView::Template::Error (undefined method events_path' for #<#:0x007fc08b3fa838>): 1: Events 2: 3: <%= search_form_for #search do |f| %> 4: <%= f.text_field :name_cont, class: "radius-left expand", placeholder: "Event Name" %> 5: <% end %> 6: app/views/events/index.html.erb:3:in_app_views_events_index_html_erb___2056451196739971413_70232473324180'
when I rake routes, I get:
events_show GET /events/show(.:format) events#show
events_index GET /events/index(.:format) events#index
so i assume if I could get this form to point to events_index_path, it would work as expected.
what do I need to do to specify the correct path for the form?
Tbh i am not sure what i did to get this working. here is my controller index action now, which includes a distance/location search feature:
def index
if params[:within].present? && (params[:within].to_i > 0)
#search = Event.near(params[:location],params[:within]).search(params[:q])
else
#search = Event.search(params[:q])
end
#events = #search.result
end

Rails 4 using partials in a mailer view

I have here a problem with partials in a view of an ActionMailer. They just do not work - and I do not know, if I do something wrong, this is a bug or this is not supported at all.
This should be working as this would be needed to have also DRY code in the mailer views (. From my testings, I see, that helpers are working (after including them into the ActionMailer class)
I am using: Rails 4.0.0 on Ruby 2.0.0-p247
Error Message:
ActionView::MissingTemplate at /events/81/user_invitations
==========================================================
> Missing partial user_invitation_mailer/test_partial with {:locale=>[:en], :formats=>[:text], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}. Searched in:
* "/Users/user/Sites/participate/app/views"
* "/Users/user/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.4.0/app/views"
But this partial is there! - I am not allowed to upload pictures... structure is:
- views
-- user_invitation_mailer
--- _test_partial.html.erb
--- user_invitation.text.erb
Details:
call in the Controller:
UserInvitationMailer.user_invitation(#invitation).deliver
UserInvitationMailer:
class UserInvitationMailer < ActionMailer::Base
add_template_helper(MailerHelper) # for testing including helpers.
def user_invitation(invitation)
#invitation = invitation
mail(to: #invitation.email, subject: 'Invitation')
end
end
user_invitation.text.erb:
Hi <%= #invitation.email %>,
This is a test email see:
<%# test_helper %>
<%= render partial: 'test_partial' %>
Thanks
_test_partial.html.erb:
"Test the partial."
(adding:)
Not working:
<%= render partial: 'test_partial' %>
<%= render partial: './test_partial' %>
<%= render partial: '../test_partial' %>
<%= render partial: 'user_invitation_mailer/test_partial' %>
The rails console give you nice explanation where it is looking for partials:
Missing partial user_invitation_mailer/test_partial with {:locale=>[:en], :formats=>[:text], :handlers=>[:erb, :builder, :raw, :ruby, :coffee]}.
Searched in:
"/Users/user/Sites/participate/app/views"
So the root folder for partials is your views folder.
You can create new folder:
/views/partials/_some_partial.html.erb
and in your template:
render "partials/some_partials", local_variables: #model.some_variables
or just render full path partial:
render "/user_invitation_mailer/test_partial"
UPD
For complete answer please see comments below
in rails 4 you can try with <%= render 'test_partial' %> it will work.
Were you able to find a solution? I am having the same issue. But able to render a partial if defined some shared folder.
Edit - Found the issue. I was not properly closing the call.

Indicate that an uploaded file is present in edit form -- paperclip

In my current solution, I am able to put a checkbox in the edit form so that users can delete attachment. However, there is no indication for the user that a file has been uploaded, the name of that file, etc. so that he can decide whether to delete.
Right now the form look like this. The first material is an existing one, the next 3 are due to
def edit
#post = Post.find(params[:id])
3.times { #post.post_materials.new }
end
As you can see, it's very hard to distinguish between them. Ideally, I want the first material file name to appear somehow.
<%= form_for #post, :html => { :multipart => true } do |f| %>
<%= f.label :title %>
<%= f.text_field :title %>
Materials:
<ul>
<%= f.fields_for :materials, :html => { :multipart => true } do |materials_form| %>
<li>
<%= materials_form.label :asset %>
<%= materials_form.file_field :asset %>
<%= materials_form.label :_destroy, class: "checkbox inline" do %>
Remove attachment <%= materials_form.check_box :_destroy %>
<% end %>
</li>
<% end %>
</ul>
<%= f.submit "Submit", class: "btn btn-large" %>
<% end %>
Running paperclip's generator creates a migration to add 4 attributes on your model, as you can see here. These attributes are:
<attachment>_file_name
<attachment>_file_size
<attachment>_content_type
<attachment>_updated_at
So, If you ran the generator this way: rails generate paperclip post_material asset, on your PostMaterial model, you will have these attributes:
asset_file_name
asset_file_size
asset_content_type
asset_updated_at
Then, on your code you can do something like this:
if materials_form.object.asset.exists? #object represents the current post_material instance
#show a label with object.asset_file_name
else
#render materials_form.file_field :asset
end

Adding a Class to a link_to Helper With Only 1 Parameter

I have the following:
<% #users.each do |user| %>
<% if user.profile %>
<%= link_to user do %>
<h2><%= user.profile.first_name %> <%= user.profile.last_name %></h2>
<% end %>
<% end %>
<% end %>
The above code works fine. What this code does is that it will output the first and last names of every user. These names are clickable and will take me to that user's page. My main issue is with the 3rd line. The issue I am having is that I am trying to get rid of the link underline, but I am unsure as to how to pass a class into it. Below is my attempt. My class "no-text-dec" is just one line of "text-decoration: none;"
<%= link_to (user, class: "no-text-dec") do %>
I'm new to Rails, but I understand that link_to has a body, url options, and then html options in that specific order, but how can I make it work in this case? The above line makes my application is crash, but it's the only thing I can think of that makes sense. I'm assuming it's because I am not giving it its body argument, but I'm not sure what that would be.
This should work fine if user contains url/path correct
<%= link_to(user, class: 'some_class') %> do
<span>Delete</span>
<% end %>
The space after method in sending argument in helper method link_to is crashing your application
you can give a try at irb
def test(a,b)
puts a; puts b;
end
test ("Ad","Cd")
It should throw an error