Turbo Stream not updating view Rails 6.1 upgrade to Turbo - ruby-on-rails

It looks like my view should be updating. From the rails console it looks successful but my view does not update
I have this in my view
#views/pos_systems/sales.html.erb
<%= turbo_stream_from #sale %>
<%= turbo_stream.update dom_id(#sale), partial: "sales/sale" %>
<div id:"<%= dom_id (#sale) %>">
<%= render 'sales/sale', sale: #sale %>
</div>
the partial is in
#views/sales/_sale.html.erb
<h2><i class='far fa-snowflake fa-spin'></i> ...<%= #sale.comments %> </h2>
This what my console has when I do a broadcast_update, this will actually have the correct output but it does not change in my view
[132] pry(main)> s.broadcast_update
Rendered sales/_sale.html.erb (Duration: 0.1ms | Allocations: 8)
[ActionCable] Broadcasting to Z2lkOi8vanVtcHN0YXJ0LWFwcC9TYWxlLzMzOQ: "<turbo-stream action=\"update\" target=\"sale_339\"><template> <h2><i class='far fa-snowflake fa-spin'></i> ...Processing </h2> \n\n</template></turbo-stream>"
On my server I can see that it updated but the view never did
[ActionCable] [User 44] Turbo::StreamsChannel transmitting "<turbo-stream action=\"update\" target=\"sale_339\"><template> <h2><i class='far fa-snowflake fa-spin'></i> ...Processing </h2> \n\n</template></turbo-stream>" (via streamed from Z2lkOi8vanVtcHN0YXJ0LWFwcC9TYWxlLzMzOQ)
=> 1

Related

Form_with, using a range, output pdf, get instead of post Ruby on Rails

My users can add in inventory and then print all the inventory out into lables using a pdf. This part works, now I need to create a form to get the range for items to be printed. The params come over and the all my variables are correct when I check them with byebug.
First issue is that my form wants to post instead of get
No route matches [POST] "/excute_print_tags.pdf"
Now if I add the Route the code runs and no output and I get this in the command line
Inventory Load (0.4ms) SELECT "inventories".* FROM "inventories" WHERE "inventories"."user_id" = $1 AND "inventories"."print_ref" >= $2 AND "inventories"."print_ref" < $3 [["user_id", 1], ["print_ref", 4], ["print_ref", 7]]
↳ app/pdfs/inventory_landscape_pdf.rb:18:in `inventory_number'
Rendering text template
Rendered text template (Duration: 0.0ms | Allocations: 2)
Sent data Westcoast Board and Ski_myskiswapinvenotry2020-08-05 14:51:40 -0700.pdf (0.9ms)
Completed 200 OK in 65227ms (Views: 0.6ms | ActiveRecord: 8.6ms | Allocations: 220205)
form code inside views/inventories/print_tags.html.erb
<%= form_with url: excute_print_tags_path(format: "pdf") do |form| %>
<div class="flex flex-wrap -mx-3 mb-2">
<div class="w-full md:w-1/3 px-3 mb-6 md:mb-0">
<div class="form-group">
<%= form.label :print_ref1 %>
<%= form.number_field :print_ref1, class: "form-control" %>
</div>
</div>
<div class="w-full md:w-1/3 px-3 mb-6 md:mb-0">
<div class="form-group">
<%= form.label :print_ref2 %>
<%= form.number_field :print_ref2, class: "form-control" %>
</div>
</div>
<div class="w-full md:w-1/3 px-3 md:mb-0 mt-8 ">
<div class="form-group">
<%= form.button class: "btn btn-primary" %>
</div>
</div>
</div>
<% end %>
Then inside the controllers/inventories_contoller
def excute_print_tags
#print_ref1 = params[:print_ref1]
#print_ref2 = params[:print_ref2]
#filtered_inventory = #user_inventory.where(print_ref: #print_ref1...#print_ref2)
byebug
respond_to do |format|
format.html
format.pdf do
pdf = InventoryLandscapePdf.new(#filtered_inventory)
send_data pdf.render, filename: "#{current_user.company}_myskiswapinvenotry#{Time.new}.pdf",
type: "application/pdf",
disposition: "inline"
end
end
end
I have also tried adding the above code to print_tags section of the inventories and calling to itself. Same problem ... I think it has something to do with the way my forms is and it is only allowing it to be sent as a post instead of a get, technically its just a search right? I did try a search for that I found but that didnt solve this issue either. Any help is appreciated.
I had to change this line
<%= form_with url: excute_print_tags_path(format: "pdf") do |form| %>
To this line
<%= form_with url: excute_print_tags_path(format: "pdf"), local: true, method: :get do |form| %>
Thanks Les for your help

Ruby on Rails full calendar gem ActionView::Template:Error

I've been working on a ruby on rails app and trying to integrate the full calender gem but am experiencing errors. I can get the calendar to display but not the module to display to enter new events, every time I fix an error I seem to run into another.
I'm currently getting an ActionView::Template::Error
In my console
Started GET "/entries/new?_=1492426544714" for ::1 at 2017-04-17 11:55:52 +0100
Processing by EntriesController#new as JS
Parameters: {"_"=>"1492426544714"}
Rendered entries/_form.html.erb (46.9ms)
Rendered entries/_new.html.erb (78.2ms)
Rendered entries/new.js.erb (109.6ms)
Completed 500 Internal Server Error in 141ms (ActiveRecord: 0.0ms)
ActionView::Template::Error (undefined method `entries_index_path' for #<#<Class:0x61746a8>:0x9f321c0>):
1: <%= simple_form_for #entry, remote: true do |f| %>
2: <div class="form-inputs">
3: <%= f.input :title %>
4: <%= f.input :date_range, input_html: { class: "form-control input-sm date-range-picker" } %>
app/views/entries/_form.html.erb:1:in `_app_views_entries__form_html_erb___640013074_85163292'
app/views/entries/_new.html.erb:9:in `_app_views_entries__new_html_erb__917401192_85193628'
app/views/entries/new.js.erb:1:in `_app_views_entries_new_js_erb__613427356_85255440'
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.0ms)
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (0.0ms)
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb (78.1ms)
new.js.erb
$('#remote_container').html('<%= j render "new" %>');
$('#new_entry').modal('show');
_new.html.erb
<div class="modal fade" id="new_entry">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Create New Event</h4>
</div>
<div class="modal-body">
<%= render 'form', entry: #entry %>
</div>
</div>
</div>
</div>
any ideas?
It is a Rails magic, when you don't specify second option(url) for simple_form_for, Rails try to set it, in your case <%= simple_form_for #entry do |f|%> converts by Rails to <%= simple_form_for #entry, url: entries_index_path do |f|%>. In your routes, there is no such _path helper(as error says).
To resolve this issue run bundle rake routes and set the right url option.
Check the documentation

rails4 show method only half rendering on web, instead renders fine on terminal

ok this is prob something very easy and im prob doing something very wrong.. I have not played with rails in 2-3 years.
but like the topic says. I get the results on the terminal(linux xterm) output of a "rails s"
result:
Started GET "/rssfeeds/1" for 127.0.0.1 at 2014-05-14 04:10:45 -0400
Processing by RssfeedsController#show as HTML
Parameters: {"id"=>"1"}
Rssfeed Load (2.7ms) SELECT "rssfeeds".* FROM "rssfeeds" WHERE "rssfeeds"."id" = ? LIMIT 1 [["id", 1]]
HakTip 97 – NMap 101: Advanced Scanning Techniques
http://hak5.org/episodes/haktip-97
Hak5 1612 – Drone Basics and Open Source Ship Tracking
http://hak5.org/episodes/hak5-1612
HakTip 96 – NMap 101: Discovery Options Part 2
http://hak5.org/episodes/haktip-96
Hak5 1611 – Open Source Drones and Android SDR
http://hak5.org/episodes/hak5-1611
HakTip 95 – NMap 101: Scanning Networks Using Alternative Packets
http://hak5.org/episodes/haktip-95
Hak5 1610 – Identify And Locate Ships Via AIS Transmissions!
http://hak5.org/episodes/hak5-1610
Hak5 1609 – Tracking Aircraft over 300 miles away! Mountain + Drone + SDR
http://hak5.org/episodes/hak5-1609
Pivoting In Metasploit – Metasploit Minute
http://hak5.org/episodes/metasploit-minute/pivoting-in-metasploit-metasploit-minute
HakTip 94 – NMap 101: Scanning Networks For Open Ports To Access
http://hak5.org/episodes/haktip-94
Hak5 1608 – The Earth is ROUND! All about Radio Horizon
http://hak5.org/episodes/hak5-1608
Linux Persistance – Metasploit Minute
http://hak5.org/episodes/metasploit-minute/linux-persistance-metasploit-minute
Rendered rssfeeds/_feed.html.erb (1.3ms)
Rendered rssfeeds/show.html.erb within layouts/application (43.8ms)
Completed 200 OK in 963ms (Views: 544.4ms | ActiveRecord: 2.7ms)
but of course I need that to render on the view..
here is my method in the controller:
def show
unless #rssfeed.url.nil?
#feeds = Feedjira::Feed.fetch_and_parse(#rssfeed.url)
end
end
here is my view (show.html.erb) that is the default and I added a render to call a _feed.html.erb file.
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= #rssfeed.name %>
</p>
<p>
<strong>Url:</strong>
<%= #rssfeed.url %>
</p>
<%= render 'feed' %>
<%= link_to 'Edit', edit_rssfeed_path(#rssfeed) %> |
<%= link_to 'Back', rssfeeds_path %>
ok here is the last part: where is supposed to happen(file _feed.html.erb)
<ul>
<% #feeds.entries.each do |line| %>
<li> <%= puts line.title %> <%= puts line.url %> </li>
<% end %>
</ul>
any ideas? I had this happen to me before when in my view I had something different than in my controller like the method name will not be the same of my view.. but I have double check and as far I can see is all ok.
remove puts from the file file _feed.html.erb
puts print the output in the console and nil gets returned which in turn gets printed on the page, thats why no output.
<ul>
<% #feeds.entries.each do |line| %>
<li> <%= puts line.title %> <%= puts line.url %> </li>
<% end %>
</ul>
to
<ul>
<% #feeds.entries.each do |line| %>
<li> <%= line.title %> <%= line.url %> </li>
<% end %>
</ul>

Rails - Passing a parameter from one view to a different controller

Fairly simple question, and I've seen lots of similar ones asked in my search, but none of the solutions I've read have worked so far. Not sure where I'm going wrong.
In my application I have Projects and Verifications. When viewing a particular Project, I need to be able to have a link to "Verify Project", which will send the user to a new Verification form. They will enter a variety of values, but I do not want them to have to select the Project that this Verification belongs to by hand -- I want to be able to pass the project_id directly alongside the values the user enters in the Verification form.
On my project view I have:
<%= link_to "Verify Project", new_verification_path(:project_id => #project.id ) %>
and then in the verifications controller:
def new
#verification = Verification.new(params[:verification])
#project = params[:project_id]
end
def create
#verification = Verification.new(params[:verification])
#verification.project = #project
end
but this yields this error:
Validation failed: Project does not exist, Project does not exist
How can I create my Verification with :project_id being grabbed from the previous page?
EDIT
From the Rails log:
(clicking Verify Project)
Started GET "/verifications/new?project_id=4" for 127.0.0.1 at
2013-09-10 04:02:56 +0200 Processing by VerificationsController#new as
HTML Parameters: {"project_id"=>"4"} Rendered
verifications/_form.html.erb (91.3ms) Rendered
verifications/new.html.erb within layouts/application (97.5ms)
Rendered layouts/_shim.html.erb (0.3ms) Account Load (0.2ms) SELECT
"accounts".* FROM "accounts" WHERE "accounts"."remember_token" =
'NuxEYIjeCYyFklN7EyHTDQ' LIMIT 1 Rendered layouts/_header.html.erb
(38.6ms) Rendered layouts/_footer.html.erb (0.3ms) Completed 200 OK
in 381ms (Views: 368.4ms | ActiveRecord: 2.7ms)
and then Create
Started POST "/verifications" for 127.0.0.1 at 2013-09-10 04:03:04
+0200 Processing by VerificationsController#create as HTML Parameters: {"utf8"=>"✓",
"authenticity_token"=>"sqUBXqA6y5oKCW1DFAi3sv8rQzm+tKjOYDdc/lvUS+c=",
"verification"=>{"verifier_name"=>"test", "checked_on(1i)"=>"2013",
"checked_on(2i)"=>"9", "checked_on(3i)"=>"10", "notes"=>"test"},
"commit"=>"Create Verification"} Account Load (0.2ms) SELECT
"accounts".* FROM "accounts" WHERE "accounts"."remember_token" =
'NuxEYIjeCYyFklN7EyHTDQ' LIMIT 1 (0.0ms) begin transaction
(0.1ms) rollback transaction Completed 422 Unprocessable Entity in
18ms
ActiveRecord::RecordInvalid (Validation failed: Project does not
exist, Project does not exist):
app/controllers/verifications_controller.rb:55:in `create'
EDIT 2
Here's the form for the Create action:
<%= form_for(#verification) do |f| %>
<% if #verification.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#verification.errors.count, "error") %> prohibited this verification from being saved:</h2>
<ul>
<% #verification.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="row">
<div class="span6 offset3">
<div class="field">
<%= f.label :verifier_name %><br />
<%= f.text_field :verifier_name %>
</div>
<div class="field">
<%= f.label :checked_on %><br />
<%= f.date_select :checked_on %>
</div>
<div class="field">
<%= f.label :notes %><br />
<%= f.text_area :notes %>
</div>
<div class="actions">
<%= f.submit %>
</div></div></div>
<% end %>
Your new controller action is a bit off. You're assigning an actual id to the #project instance variable, rather that the Project object that corresponds to that id. Subsequently, you're passing an invalid id from your new view to your create action.
Fix things by properly assigning the #project instance variable in your new action:
def new
#verification = Verification.new(params[:verification])
#project = Project.find(params[:project_id])
end
Then, you'll need to do a proper lookup of the a Project object in your create action:
def create
#verification = Verification.new(params[:verification])
#verification.project = Project.find(params[:project_id])
#verification.save
end
Finally, add the project_id as parameter in your form via the hidden_field form helper tag:
# in your `create` form
<%= f.hidden_field :project_id, :value => #project.id %>
You need to be sure that your project id is passed back to your create method. You can look up the project as in zeantsol's answer, or you can just pass the project ID. But you need to make sure that the form you create in your "new" view passes the project id back to your create method (perhaps in a hidden field)
See this post to see an example of using a hidden field in your view:
Rails hidden field undefined method 'merge' error

RoR: partials with resources

I have a problem, trying to render partials in ruby on rails with the short notation for resoures. Somehow, RoR displays simply nothing that has to do with the partial, but i get no errors as well. I mean, the resulting HTML looks like the call for the partial simply wouldn't be there. I'm also confused, because i can see in the log, that rails rendered the partial 2 times (that would be ok, i have two test entries in the dev db), but i get no output in the browser. What am i doing wrong? Thanks in advance! This is my code:
app/views/tutorials/_tutorial.html.erb:
<div class="tutorial">
<h3><%= link_to tutorial.title, tutorial %></h3>
<span class="person"><%=h tutorial.tutor %></span>
<span class="time"><%=h german_time(tutorial.starts_at) %></span>
<span class="location"><%=h tutorial.location %></span>
<div class="description"><%=h tutorial.description %></div>
<% if admin? %>
<%= link_to 'Edit', edit_tutorial_path(tutorial) %> |
<%= link_to 'Delete', tutorial, :confirm => 'Are you sure?', :method => :delete %>
<% end %>
</div> <!-- end .tutorium -->
app/views/tutorials/index.html.erb:
<h2>Tutorials</h2>
<% render :partial => #tutorials %>
<% if admin? %>
<%= link_to 'New Tutorial', new_tutorial_path %>
<% end %>
console log:
Processing TutorialsController#index (for 127.0.0.1 at 2009-12-07 23:39:00) [GET]
Tutorial Load (0.6ms) SELECT * FROM "tutorials"
Rendering template within layouts/application
Rendering tutorials/index
Rendered tutorials/_tutorial (7.1ms)
Rendered tutorials/_tutorial (3.7ms)
Completed in 22ms (View: 17, DB: 1) | 200 OK [http://localhost/tutorials]
Try it with an equals:
<%= render :partial => #tutorials %>

Resources