How do I add session variable to view markup? [duplicate] - asp.net-mvc

This question already has answers here:
Accessing a Session object from Razor _Layout.cshml
(2 answers)
Closed 7 years ago.
I am trying to add a session variable to html markup using MVC Razor, I tried this:
<div class="panel-body">
<p>It might suprise you to know that you can upgrade from #Session("CurrentProvider") to blah blah....</p>
</div>
I tried wrapping it in code tags and all sorts. How can I fix this?

Seems the answer is to append with ToString
#Session("CurrentProvider").ToString

Related

View all instance variables currently available? (Ruby) [duplicate]

This question already has answers here:
Is there a way to list the available variables in an Ruby ERB template?
(1 answer)
Get all instance variables declared in class
(5 answers)
Closed 6 years ago.
I have been asked to work on a large project (already half-done). One file I'm working on starts with this:
<div class="table-responsive">
<table class="table">
<% if #incidents.present? %>
<br>
<thead>
I didn't know #incidents existed, until I saw it referenced. It made me wonder—what other instance variables are available for me to use? How would I know?
Because this is a big project with many files interacting, I don't want to just look at the controller or something like that, I want a way to log all instance variables available to me at a particular point in the code.
#foo = 3
instance_variables # => [:#foo]

Add html content to faces message from Backing Bean [duplicate]

This question already has answers here:
How do I add HTML code to JSF FacesMessage
(4 answers)
Closed 7 years ago.
I need to add a Html content when some method returns the wanted result (any method, any result) to the JSF page exactly like primefaces do with .
Html to add is simple :
<div class="alert alert-success" role="alert">
<strong>Well done!</strong> You successfully read this important alert message.
</div>
But can't find a way to do this cleanly, I've read many posts like How do I return HTML from managed bean in JSF? but my bean need to insert that html when user is doing something e.g. submitting a form result.
Also : is there a way to save it and show it in case of a redirection like it is with primefaces context.getExternalContext().getFlash().setKeepMessages(true);
Why not simply using h:messages tag ? It is fully customizable in terms of design and you can simply affect your styles and class without all the turn-around
Source : http://www.jsftoolbox.com/documentation/help/12-TagReference/html/h_messages.html

How to summit a post with line break in rails? [duplicate]

This question already has answers here:
Preserve newline in text area with Ruby on Rails
(3 answers)
Closed 8 years ago.
It seems like rails treat every post with line break by change the line break into a space.
for example:
when I type
hi
hi
hi
in my form, what I get is just a simple "hi hi hi". How to change that?
I assume that in post form for description field you may have taken textarea
as Rustam commented you can use simple_format helper method: Two or more consecutive newlines(\n\n) are considered as a paragraph and wrapped in <p> tags.
You can use like
<%= simple_format(#post.description) %>
I hope this work out for you..

Get raw HTML on current page [duplicate]

This question already has answers here:
Rendering a Rails view to string for email
(4 answers)
Closed 8 years ago.
I need to get the HTML code of the current page in Rails.
In the controller's action I need a string with that HTML code, for example:
<html><head></head><body><p>Hello</p></body></html>
The problem looks easy, but I can't find the solution.
If you need to render the output of an action as a string:
html = render_to_string(...)
It generally takes the same options as render but gives you the result you can work with instead of sending it to the client.

Using Ruby and HTML together [duplicate]

This question already has answers here:
Embedding Ruby code in HTML?
(3 answers)
Closed 9 years ago.
Is it possible to put Ruby code in the HTML page which has a extension ".rhtml"?
For example, I want to use a HTML form and then some Ruby code. Does it have to be encapsulated in the <% tags?
The file extension should be ".html.erb" for Rails 3 or above.
The Ruby code should be between <% %> for logic statements, or between <%= %> if you want to display the results of the code.
".erb" is what you are looking for. Rails uses ".erb" files and it is possible to embed Ruby code inside them.

Resources