Rails in Rendering Unnecessary Information

Rails rendering partials even when commented out

I had always assumed that partials render at the time the line of code is run.

The key here is understanding when the code is run. When you dynamically create javascript with js.erb the file is first run through ERB on the server before it is sent to the client which runs the resulting javascript. Your server does not actually parse the javascript so it does not know or care that there is a event handler involved. To Rails its just a string buffer.

This is actually a major conceptual problem with js.erb templates as the context switching between server and client side makes the flow hard to follow.

There are also numerous other problems with this code like the use of the === identity operator and the fact that your performing DB queries in the view which is a huge anti-pattern.

How to make Rails stop logging every page rendering?

take a look at your config/environments/production.rb file for the config.log_level variable.

Keep in mind however, that on a database failure, you can use the info statements to recreate data lost via user input between last db backup and database restore.

other tips and suggestions here

Rails 4 content_for and yield displays blank page

Why are you rendering partials as the views for your actions?

def manage_accounts
@accounts = Account.order('id').page(params[:page]).per(15)
render partial: 'manage_accounts'
end

Calling render partial like this will only render the content of the partial and will not load the layout. If you want the layout (and it certainly sounds like you do) then rename this file to a normal view app/views/administrators/manage_accounts.html.erb and then remove the render call from your action altogether.

I would also advise splitting each of these manage routes out into their own controllers, so instead you would have app/views/admin/accounts/index.html.erb, which would become the new view to manage accounts. I suggest this because it falls in line with the more traditional CRUD design of a Rails application.

Trouble rendering data attributes in Haml, Rails

To achieve the same HTML output of ERB using HAML

= form_tag charges_path do
%h4 So what comes with being a Blocipedia premium member?
%p The ability to create your very OWN private wikis of course!
%script.stripe-button{data: {key: @stripe_btn_data[:key], amount: @stripe_btn_data[:amount], description: @stripe_btn_data[:description]}, src: "https://checkout.stripe.com/checkout.js"}

Rails 7 rendering to a VTT, displays entity code instead of character

Rails escapes everything in the view by default. However, you can circumvent sanitisation by using raw:

= raw(cue.start_time.strftime("%H:%M:%S.%L") + @dash + cue.end_time.strftime("%H:%M:%S.%L"))

or, haml-specific, the != operator has the same effect as prepending raw:

!= cue.start_time.strftime("%H:%M:%S.%L") + @dash + cue.end_time.strftime("%H:%M:%S.%L")

(In ERB, <%== %> would have the equivalent effect.)

Error when rendering rails form_tag partial

Use render partial: instead of render

<%= render partial: "form_partial_name", locals: { form_url: url_A } %>
<%= render partial: "form_partial_name", locals: { form_url: url_B } %>

Because render don't support locals.

Read more.

There is also another way. You can also use yield and provide:

<%= form_tag yield(:form_url), method: 'GET' do %>
<%= ... %>
<%= ... %>
<%= submit_tag 'Submit' %>
<% end %>

And 2 different views:

<% provide(:form_url, url_A) %>
<%= render "form_partial_name" %>
<% provide(:form_url, url_B) %>
<%= render "form_partial_name" %>


Related Topics



Leave a reply



Submit