Rails 5.2.0 - scaffold `form_with` includes `local: true` by default - forms

When I scaffold a Rails 5.2.0 app, my scaffolded forms are always generated with the local: true option included in form_with.
rails g scaffold Article title:string
Generated scaffold form
<%= form_with(model: article, local: true) do |form| %>
<% 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 |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
Generated HTML
<form action="/articles/1" accept-charset="UTF-8" method="post">
Note the lack of data-remote attribute
Documentation
I thought the default for form_with in Rails 5.1.2+ was to use remote AJAX / xhr requests with data-remote attributes? In other words, NOT include the local: true option.
See: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_with
By default form_with attaches the data-remote attribute submitting the form via an XMLHTTPRequest in the background if an Unobtrusive JavaScript driver, like rails-ujs, is used. See the :local option for more.
Note - rails-ujsgem was moved into Rails itself in 5.2.0 - https://github.com/rails/rails-ujs. So it looks like I should not need to add anything to the gemfile to enable the default form_with behavior.
Troubleshooting
I do use a .railsrc and a rails template file to customize my rails new scaffolds. However, I have tried disabling & removing both files and still get same results from new scaffolded apps.

To give a more complete answer based on my comment, here's how to add a template to customize the form partial generated by Rails when using the scaffold generator. I'm assuming here that you're using ERB, but the procedure is similar if you're using something like slim-rails to customize your view generators.
Create a file in your Rails project: lib/templates/erb/scaffold/_form.html.erb.tt
For this new file's content, a good place to start from is the content in the existing template. You can use gem which rails to locate the file that defines Rails in your current environment (with a result like /home/<user>/.rvm/gems/ruby-2.5.0#<gemset>/gems/railties-5.2.0/lib/rails.rb), and from there you can find the form template in railties-5.2.0/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt. Copy the contents of that file into your new generator template.
Try making some changes to the new template file, and then run the rails scaffold generator (rails g scaffold foo ...). You should see your changes reflected in the _form.html.erb file created by the generator.
Bear in mind that this template is 'doubly nested' ERB, meaning that it is processed with ERB a first time to produce a view partial, and then processed again every time your Rails app serves a request with it. That said, it's usually not too mind-melting to make a simple change, such as removing local: true from your new template
In depth info on customizing Rails generators is available at RailsGuides.

Think I found answer - and it's simple :) - the Rails scaffold templates for 5.2.0 explicitly include the local: true option.
5.2.0 Template for forms
<%%= form_with(model: <%= model_resource_name %>, local: true) do |form| %>
So I guess they wanted local: true as the default template for scaffolds. Probably for simplicity?
To find the scaffold generator templates
Thanks to this post for helping find the source: Override Rails scaffold generator
Find where your gems live with gem enviornment command
I use rbenv, so mine are at ~/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems
cd into that file and look for railties-5.2.0
search in rails/generators/scaffold/templates, or just search for local: true
here's the path: ~/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.0/lib/rails/generators/erb/scaffold/templates/_form.html.erb.tt

Related

Email templates using bamboo without phoenix

I am working on app in elixir. It sends email to clients. I am using bamboo library for sending emails.
So far, emails are working fine. But now, I am trying to send emails using templates.
Everywhere i see in the bamboo documentation is using
bamboo.phoenix .
I am not using phoenix for handling requests. I am using a library called plug. Is there a way to send templates in email without phoenix ??
Adding answer to this post with the help #JustMichael comment.
Directory structure -
/priv
/static
/test.html.eex
Function used :
new_email
|> to("vivek29vivek#gmail.com")
|> from(#from_email)
|> subject("test")
|> html_body(EEx.eval_file("priv/static/mail_templates/#test.html.eex",[foo: "bar"])) //this will render the template.Also can pass variables
test.html.eex
<h3>Foo: <%= foo %></h3>
But , we cannot add css just by adding <link rel="stylesheet" href="styles.css"> . I guess, There is a need for static server.
Do comment if there is another way to add css apart from inline css.

Change the friendly URL of a web content in Liferay

I am currently using an article display page to display my web content in Liferay 6.2. I'm trying to figure out how to edit the path of my friendly URL after the /-/.
Current URL: siteName/-/articleName
Desired URL: siteName/-/topicSection/articleName
You are talking about the attribute JournalArticle.urlTitle. The problem is, that there is no UI in Liferay, which lets you change that attribute (at least not out of the box).
You've got two options:
If you just want to change an existing article, you can change that attribute in the database (I'd guess that the additional / is no problem):
UPDATE JournalArticle
SET urlTitle = 'topicSection/articleName'
WHERE urlTitle = 'articleName'
If you want to offer an UI for editing that attribute, you could write a hook.
Here a short summary how to write such a hook:
Add this lines to your liferay-hook.xml:
<portal-properties>portal.properties</portal-properties>
<language-properties>Language.properties</language-properties>
<custom-jsp-dir>/WEB-INF/custom_jsps</custom-jsp-dir>
Create a file portal.properties in the Java source directory and add this line:
journal.article.form.update = urlTitle
Create a file Language.properties in the Java source directory and add this line:
urlTitle = Friendly URL
Add a file WEB-INF/custom_jsps/html/portlet/journal/article/urlTitle.jsp into the web content folder:
<%# include file="/html/portlet/journal/init.jsp" %>
<% JournalArticle article = (JournalArticle)request.getAttribute(WebKeys.JOURNAL_ARTICLE); %>
<aui:model-context bean="<%= article %>" model="<%= JournalArticle.class %>" />
<h3>Friendly URL</h3>
<aui:input name="urlTitle" />

unable to instantiate CQ.utils.WCM in cq publish mode

I'm unable to instantiate CQ.utils.WCM in CQ publsih mode to get pagePath using the function CQ.utils.WCM.getPagePath(), but I can able to get the pagePath in CQ Author mode using the same function. Can somebody help me why
CQ.utils.WCM.getPagePath() function not executing in jsp file in cq publish crxde lite
Thank you for your help!
Naren
Possibly because your AEM specific client libraries would not have been included in publish mode (i.e., when WCMMODE is disabled) and this is an ideal scenario.
The clientlibs might have been included as shown below
<% if(WCMMode.fromRequest(request) != WCMMode.DISABLED) { %>
<cq:includeClientLib categories="cq.widgets" />
<%-- or --%>
<cq:includeClientLib categories="cq.wcm.edit" />
<% } %>

Include Build request user in jenkins groovy email

After a build is finished I use the mail-ext-plugin (Jenkins Email Extension Plugin) to send an email to certain users. I would like to include the user who started (requested) the build in that email. I have tried the suggestion here however, that didn't seem to work I just got this error.
Error in script or template: groovy.lang.MissingPropertyException: No such property: CAUSE for class: SimpleTemplateScript4
After much searching I found a page on jelly usage on the Jenkins wiki (here). There is a link on this page which contains all the useable classes. I was able to find the cause class and used this great example to help me implement it in my code. I added
<%
for (hudson.model.Cause cause : build.causes) {
%>
${cause.shortDescription}
<%
}
%>
which produced -
Started by user Matthew Armstrong

Telerik Html.Grid Style Sheet issue

I started using the Telerik Html.Grid today and have already run into a problem. The Grid itself is appearing, but text based so i know this is a style sheet issue. Also, i have been following the usage instructions with the documentation. Ill go through them and explain what i did, maybe my interpretation was wrong.
1)Open an existing ASP.NET MVC application in Visual Studio or create a new one.
Done
2)Add a reference to Telerik.Web.Mvc.dll which is located in the Binaries folder of Telerik Extensions for ASP.NET MVC install location:
Done
3)Register the Telerik Extensions for ASP.NET MVC namespaces:
Done, but i used import instead of add
<%# Import Namespace="Telerik.Web.Mvc.UI" %>
4)Add the JavaScript files in the Scripts folder of your ASP.NET MVC application.
Done, but essentailly the scripts are in the location Web/Scripts/2010.2.825 I also put in the ScriptRegistrar at the end of my .aspx page
<div id="footer">
<% Html.RenderPartial("SiteMasterFooter");%>
</div>
<div style="clear: both;"><!-- --></div>
<%
Html.Telerik().ScriptRegistrar().jQuery(false);
%>
5)Add the CSS files in the Content folder of your ASP.NET MVC application.
Done. Same approach as step 4, the location is Wed/Content/2010.2.825 I also put the Style sheet registrar at the head of the aspx page
<%
Html.Telerik().StyleSheetRegistrar()
.DefaultGroup(group => group.Add("telerik.common.css")
.Add("telerik.windows7.css"));
%>
6)Create a telerik web control
Done. Dont think i can screw this up, but hey.
<%
Html.Telerik().Grid(Model.Manifests)
.Name("ManifestsGrid")
.DataKeys(keys =>
{
keys.Add(p => p.Id);
})
.Columns(columns =>
{
columns.Bound(o => o.ManifestId).Width(150).Title(
"Manifest #:");
columns.Bound(o => o.Generator.CompanyName).Width(150).Title
("Company:");
columns.Bound(o => o.GeneratorFieldOffice.FacilityName).
Width(150).Title("Field Office:");
columns.Bound(o => o.GeneratorFacility.FacilityName).Width(
150).Title("Facility:");
})
.Pageable(paging => paging.PageSize(10))
.Selectable()
.Scrollable()
.Render();
%>
So i think that my problem lies with how ive added the files i need. Any input?
I fixed it actually. For anyone reading this, the problem was that i follow the guide to the letter. And take very special care as to what <% %> tags have : or = at the beginning or a ; at the end. If this is too vague post an answer to this question and ill post my code.